276 lines
10 KiB
C#
276 lines
10 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.Models.Notifications
|
|
{
|
|
public class NotificationsRepository
|
|
{
|
|
|
|
#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 application name from AppSetting in web.config file
|
|
/// </summary>
|
|
private static string _appName = ConfigurationManager.AppSettings["ApplicationName"].ToString();
|
|
|
|
/// <summary>
|
|
/// getting web api token from AppSetting in web.config file
|
|
/// </summary>
|
|
private static string _securityToken = ConfigurationManager.AppSettings["RESTfulSecurityToken"].ToString();
|
|
|
|
/// <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 time zone id from AppSetting in web.config file
|
|
/// </summary>
|
|
private static string _TimeZoneId = ConfigurationManager.AppSettings["TimeZoneId"].ToString();
|
|
|
|
/// <summary>
|
|
/// getting rest api url from AppSetting in web.config file
|
|
/// </summary>
|
|
private static string _RestClientUrl = ConfigurationManager.AppSettings["RestfulApiUrl"].ToString();
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// get all notifications with count
|
|
/// </summary>
|
|
/// <returns>return list type of notification count</returns>
|
|
public List<NotificationDisplayModel> GetAllNotifications()
|
|
{
|
|
try
|
|
{
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/TicketStatus", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
return client.Execute<List<NotificationDisplayModel>>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_GetAllNotifications", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// get all notifications details
|
|
/// </summary>
|
|
/// <returns>return list of notification details</returns>
|
|
public List<NotificationsModel> GetNotificationsData()
|
|
{
|
|
try
|
|
{
|
|
_timeOffSetMinutes = HttpContext.Current.Session["UtcMinute"].ToString();
|
|
_LoginUserId = HttpContext.Current.Session["UserId"].ToString();
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/TicketStatus?Notification=n&Notification1=nn&Notification2=n2", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
request.AddParameter("UtcMinute", _timeOffSetMinutes);
|
|
request.AddParameter("UserId", _LoginUserId);
|
|
return client.Execute<List<NotificationsModel>>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_GetNotificationsData", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// remove seen notification details
|
|
/// </summary>
|
|
/// <param name="ticketId">ticket id</param>
|
|
/// <returns>return model notification remove</returns>
|
|
public NotificationRemove RemoveSeenNotification(string ticketId)
|
|
{
|
|
try
|
|
{
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/TicketStatus?Notification=n&Notification1=nn", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
request.AddParameter("NotificationId", ticketId);
|
|
return client.Execute<NotificationRemove>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_RemoveSeenNotification", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#region dealer notifications
|
|
|
|
/// <summary>
|
|
/// Get dealers notifications
|
|
/// </summary>
|
|
/// <returns>return notification list</returns>
|
|
public List<DealerNortificationModel> GetDealerNotifications()
|
|
{
|
|
try
|
|
{
|
|
_timeOffSetMinutes = HttpContext.Current.Session["UtcMinute"].ToString();
|
|
_LoginUserId = HttpContext.Current.Session["UserId"].ToString();
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/Dealer?notification=n", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
request.AddParameter("UserId", _LoginUserId);
|
|
request.AddParameter("UtcMinute", _timeOffSetMinutes);
|
|
return client.Execute<List<DealerNortificationModel>>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_GetDealerNotifications", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// remove seen notification details for dealers
|
|
/// </summary>
|
|
/// <param name="ticketId">ticket id</param>
|
|
/// <returns>return model notification remove</returns>
|
|
public NotificationRemove RemoveSeenNotificationDealer(string ticketId)
|
|
{
|
|
try
|
|
{
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/TicketStatus?DealerNotification=121", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
request.AddParameter("NotificationId", ticketId);
|
|
return client.Execute<NotificationRemove>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_RemoveSeenNotificationDealer", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
|
|
#region KAM notifications
|
|
|
|
/// <summary>
|
|
/// Get KAM notifications
|
|
/// </summary>
|
|
/// <returns>return notification list</returns>
|
|
public KamNotificationOutputModel GetKamNotifications()
|
|
{
|
|
try
|
|
{
|
|
_timeOffSetMinutes = HttpContext.Current.Session["UtcMinute"].ToString();
|
|
_LoginUserId = HttpContext.Current.Session["UserId"].ToString();
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/notification", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
request.AddParameter("UtcMinute", _timeOffSetMinutes);
|
|
return client.Execute<KamNotificationOutputModel>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_GetKamNotifications", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// remove seen notification details for KAM
|
|
/// </summary>
|
|
/// <param name="notificationId">notification id</param>
|
|
/// <returns>return model notification remove</returns>
|
|
public KamNotificationOutputModel RemoveSeenNotificationKam(string notificationId)
|
|
{
|
|
try
|
|
{
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/notification?deleteKamNotification=dd", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
request.AddParameter("NotificationId", notificationId);
|
|
return client.Execute<KamNotificationOutputModel>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_RemoveSeenNotificationKam", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// remove KAM ticket in case of decline ticket by CCE
|
|
/// </summary>
|
|
/// <param name="kamTicketId">KAM Ticket Id</param>
|
|
/// <returns>return model ticket remove</returns>
|
|
public DenyKamTicket RemoveKamTicket(Int32 kamTicketId)
|
|
{
|
|
try
|
|
{
|
|
_LoginUserId = HttpContext.Current.Session["UserId"].ToString();
|
|
|
|
var client = new RestSharp.RestClient(_RestClientUrl);
|
|
var request = new RestRequest("Api/ticket?deleteKamticket=1", Method.POST);
|
|
request.AddParameter("Token", _securityToken);
|
|
request.AddParameter("kamticketid", kamTicketId);
|
|
request.AddParameter("userid", _LoginUserId);
|
|
return client.Execute<DenyKamTicket>(request).Data;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
objLog.ErrorLogFile("NotificationRepository_RemoveKamTicket", ex.Message, path, errorlogtf);
|
|
throw ex;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |