using LoggingHelper; using System; using System.Collections.Generic; using System.Configuration; using System.Linq; using System.Web; using System.Web.Mvc; using GODATA.RoleServices; using GODATA.AuthenticationServices; using RestSharp; using Newtonsoft.Json; using GODATA.Models.Ticket; using Kendo.Mvc.UI; using Kendo.Mvc.Extensions; using GODATA.Models.Notifications; namespace GODATA.Controllers { [GODATA.MvcApplication.SessionExpire] public class NotificationsController : Controller { /// /// Global variable for Notifications repository. /// private NotificationsRepository objNotificationsRepository = null; #region Global Variables /// /// Represent object of LoggingUtility class /// LoggingUtility objLog = new LoggingUtility(); /// /// Represent string object contain log file path /// //string path = "~/Log/"; string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]); /// /// Represent string object contain log status /// string logtf = (ConfigurationManager.AppSettings["Log"]); /// /// Represent string object contain Error log status /// string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]); /// /// getting user's utc minutes from session /// private static string _timeOffSetMinutes = null; /// /// getting login user's id /// private static string _LoginUserId = null; /// /// getting login user's name /// private static string _LoginUserName = null; /// /// getting login user's role /// private static string _LoginUserRole = null; #endregion /// /// Get notifications data view /// /// returns view public ActionResult Index() { objLog.AddLogFile("Notification_Index", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); //getting notification data list List objNotificationDataList = objNotificationsRepository.GetNotificationsData(); ViewBag.NotificationCount = objNotificationDataList.Count(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return View(objNotificationDataList); } catch (Exception ex) { objLog.ErrorLogFile("Notification_Index", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Remove seen notifications from notifications data list /// /// ticket id of related notification /// return json success true or false public ActionResult RemoveSeenNotifications(string ticketId) { objLog.AddLogFile("Notification_RemoveSeenNotifications", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); //Getting model of removed notification NotificationRemove objNotificationRemoveModel = objNotificationsRepository.RemoveSeenNotification(ticketId); objLog.AddLogFile("Notification_RemoveSeenNotifications", objNotificationRemoveModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (objNotificationRemoveModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false }); } catch (Exception ex) { objLog.ErrorLogFile("Notification_RemoveSeenNotifications", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Get notifications count /// /// return json of total count of notifications public ActionResult GetNotificationsCount() { objLog.AddLogFile("Notification_GetNotificationsCount", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); int TotalNotifications = 0; //getting notification data list List objNotificationDataList = objNotificationsRepository.GetNotificationsData(); TotalNotifications = objNotificationDataList.Count(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, total = TotalNotifications }); } catch (Exception ex) { objLog.ErrorLogFile("Notification_GetNotificationsCount", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } #region dealer ntoifications /// /// Get dealer's notifications data view /// /// return view public ActionResult DealerNotifications() { objLog.AddLogFile("Notification_DealerNotifications", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); //getting notification data list List objNotificationDataList = objNotificationsRepository.GetDealerNotifications(); ViewBag.NotificationCount = objNotificationDataList.Count(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return View(objNotificationDataList); } catch (Exception ex) { objLog.ErrorLogFile("Notification_DealerNotifications", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Getting dealer notifications count /// /// return json total notifications public ActionResult GetDealerNotificationCount() { objLog.AddLogFile("Notification_GetDealerNotificationCount", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); int TotalNotifications = 0; //getting notification data list List objNotificationDataList = objNotificationsRepository.GetDealerNotifications(); TotalNotifications = objNotificationDataList.Count(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, total = TotalNotifications }); } catch (Exception ex) { objLog.ErrorLogFile("Notification_GetDealerNotificationCount", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Remove seen notifications from dealer notifications data list /// /// ticket id of related notification /// return json success true or false public ActionResult RemoveSeenNotificationsDealer(string ticketId) { objLog.AddLogFile("Notification_RemoveSeenNotificationsDealer", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); //Getting model of removed notification NotificationRemove objNotificationRemoveModel = objNotificationsRepository.RemoveSeenNotificationDealer(ticketId); objLog.AddLogFile("Notification_RemoveSeenNotificationsDealer", objNotificationRemoveModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (objNotificationRemoveModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false }); } catch (Exception ex) { objLog.ErrorLogFile("Notification_RemoveSeenNotificationsDealer", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } #endregion #region KAM's Ticket ntoifications /// /// Get KAM's notifications data view /// /// return view public ActionResult KamNotifications() { objLog.AddLogFile("Notification_KamNotifications", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); List objList = new List(); //getting notification data list KamNotificationOutputModel objNotificationDataList = objNotificationsRepository.GetKamNotifications(); objList = objNotificationDataList.NotificationList; ViewBag.NotificationCount = objList.Count(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return View(objList); } catch (Exception ex) { objLog.ErrorLogFile("Notification_KamNotifications", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Getting KAM notifications count /// /// return json total notifications public ActionResult GetKamNotificationCount() { objLog.AddLogFile("Notification_GetKamNotificationCount", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); List objList = new List(); int TotalNotifications = 0; // //getting notification data list KamNotificationOutputModel objNotificationDataList = objNotificationsRepository.GetKamNotifications(); objList = objNotificationDataList.NotificationList; TotalNotifications = objList.Count(); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true, total = TotalNotifications }); } catch (Exception ex) { objLog.ErrorLogFile("Notification_GetKamNotificationCount", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Remove seen notifications from KAM notifications data list /// /// notification id of related notification /// return json success true or false public ActionResult RemoveSeenNotificationsKam(string notificationId) { objLog.AddLogFile("Notification_RemoveSeenNotificationsKam", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); //Getting model of removed notification KamNotificationOutputModel objNotificationRemoveModel = objNotificationsRepository.RemoveSeenNotificationKam(notificationId); objLog.AddLogFile("Notification_RemoveSeenNotificationsKam", objNotificationRemoveModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (objNotificationRemoveModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false }); } catch (Exception ex) { objLog.ErrorLogFile("Notification_RemoveSeenNotificationsKam", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } /// /// Remove KAM notification and KAM ticket from KAM notifications data list /// in case of decline kam ticket by CCE /// /// KAM's ticket id of declined ticket by cce /// notification id of related notification /// return json success true or false public ActionResult RemoveKamTicket(Int32 kamTicketId, string notificationId) { objLog.AddLogFile("Notification_RemoveKamTicket", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); try { objNotificationsRepository = new NotificationsRepository(); //Getting model of decline kam ticket DenyKamTicket objTicketRemoveModel = objNotificationsRepository.RemoveKamTicket(kamTicketId); objLog.AddLogFile("Notification_RemoveKamTicket", objTicketRemoveModel, DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); if (objTicketRemoveModel.Status == "1") { objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = true }); } objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); return Json(new { success = false }); } catch (Exception ex) { objLog.ErrorLogFile("Notification_RemoveKamTicket", ex.Message, path, errorlogtf); objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf); throw ex; } } #endregion } }