EOS/Controllers/NotificationsController.cs
Nidhi Bhargava f0c1ab20e1 code push
2025-09-04 16:25:07 +05:30

389 lines
17 KiB
C#

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
{
/// <summary>
/// Global variable for Notifications repository.
/// </summary>
private NotificationsRepository objNotificationsRepository = null;
#region Global Variables
/// <summary>
/// Represent object of LoggingUtility class
/// </summary>
LoggingUtility objLog = new LoggingUtility();
/// <summary>
/// Represent string object contain log file path
/// </summary>
//string path = "~/Log/";
string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
/// <summary>
/// Represent string object contain log status
/// </summary>
string logtf = (ConfigurationManager.AppSettings["Log"]);
/// <summary>
/// Represent string object contain Error log status
/// </summary>
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
/// <summary>
/// getting user's utc minutes from session
/// </summary>
private static string _timeOffSetMinutes = null;
/// <summary>
/// getting login user's id
/// </summary>
private static string _LoginUserId = null;
/// <summary>
/// getting login user's name
/// </summary>
private static string _LoginUserName = null;
/// <summary>
/// getting login user's role
/// </summary>
private static string _LoginUserRole = null;
#endregion
/// <summary>
/// Get notifications data view
/// </summary>
/// <returns>returns view</returns>
public ActionResult Index()
{
objLog.AddLogFile("Notification_Index", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
try
{
objNotificationsRepository = new NotificationsRepository();
//getting notification data list
List<NotificationsModel> 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;
}
}
/// <summary>
/// Remove seen notifications from notifications data list
/// </summary>
/// <param name="ticketId">ticket id of related notification</param>
/// <returns>return json success true or false</returns>
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;
}
}
/// <summary>
/// Get notifications count
/// </summary>
/// <returns>return json of total count of notifications</returns>
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<NotificationsModel> 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
/// <summary>
/// Get dealer's notifications data view
/// </summary>
/// <returns>return view</returns>
public ActionResult DealerNotifications()
{
objLog.AddLogFile("Notification_DealerNotifications", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
try
{
objNotificationsRepository = new NotificationsRepository();
//getting notification data list
List<DealerNortificationModel> 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;
}
}
/// <summary>
/// Getting dealer notifications count
/// </summary>
/// <returns>return json total notifications</returns>
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<DealerNortificationModel> 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;
}
}
/// <summary>
/// Remove seen notifications from dealer notifications data list
/// </summary>
/// <param name="ticketId">ticket id of related notification</param>
/// <returns>return json success true or false</returns>
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
/// <summary>
/// Get KAM's notifications data view
/// </summary>
/// <returns>return view</returns>
public ActionResult KamNotifications()
{
objLog.AddLogFile("Notification_KamNotifications", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
try
{
objNotificationsRepository = new NotificationsRepository();
List<KamNotificationModel> objList = new List<KamNotificationModel>();
//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;
}
}
/// <summary>
/// Getting KAM notifications count
/// </summary>
/// <returns>return json total notifications</returns>
public ActionResult GetKamNotificationCount()
{
objLog.AddLogFile("Notification_GetKamNotificationCount", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
try
{
objNotificationsRepository = new NotificationsRepository();
List<KamNotificationModel> objList = new List<KamNotificationModel>();
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;
}
}
/// <summary>
/// Remove seen notifications from KAM notifications data list
/// </summary>
/// <param name="notificationId">notification id of related notification</param>
/// <returns>return json success true or false</returns>
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;
}
}
/// <summary>
/// Remove KAM notification and KAM ticket from KAM notifications data list
/// in case of decline kam ticket by CCE
/// </summary>
/// <param name="kamTicketId">KAM's ticket id of declined ticket by cce</param>
/// <param name="notificationId">notification id of related notification</param>
/// <returns>return json success true or false</returns>
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
}
}