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
///
/// 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 application name from AppSetting in web.config file
///
private static string _appName = ConfigurationManager.AppSettings["ApplicationName"].ToString();
///
/// getting web api token from AppSetting in web.config file
///
private static string _securityToken = ConfigurationManager.AppSettings["RESTfulSecurityToken"].ToString();
///
/// 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 time zone id from AppSetting in web.config file
///
private static string _TimeZoneId = ConfigurationManager.AppSettings["TimeZoneId"].ToString();
///
/// getting rest api url from AppSetting in web.config file
///
private static string _RestClientUrl = ConfigurationManager.AppSettings["RestfulApiUrl"].ToString();
#endregion
///
/// get all notifications with count
///
/// return list type of notification count
public List GetAllNotifications()
{
try
{
var client = new RestSharp.RestClient(_RestClientUrl);
var request = new RestRequest("Api/TicketStatus", Method.POST);
request.AddParameter("Token", _securityToken);
return client.Execute>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_GetAllNotifications", ex.Message, path, errorlogtf);
throw ex;
}
}
///
/// get all notifications details
///
/// return list of notification details
public List 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>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_GetNotificationsData", ex.Message, path, errorlogtf);
throw ex;
}
}
///
/// remove seen notification details
///
/// ticket id
/// return model notification remove
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(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_RemoveSeenNotification", ex.Message, path, errorlogtf);
throw ex;
}
}
#region dealer notifications
///
/// Get dealers notifications
///
/// return notification list
public List 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>(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_GetDealerNotifications", ex.Message, path, errorlogtf);
throw ex;
}
}
///
/// remove seen notification details for dealers
///
/// ticket id
/// return model notification remove
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(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_RemoveSeenNotificationDealer", ex.Message, path, errorlogtf);
throw ex;
}
}
#endregion
#region KAM notifications
///
/// Get KAM notifications
///
/// return notification list
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(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_GetKamNotifications", ex.Message, path, errorlogtf);
throw ex;
}
}
///
/// remove seen notification details for KAM
///
/// notification id
/// return model notification remove
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(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_RemoveSeenNotificationKam", ex.Message, path, errorlogtf);
throw ex;
}
}
///
/// remove KAM ticket in case of decline ticket by CCE
///
/// KAM Ticket Id
/// return model ticket remove
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(request).Data;
}
catch (Exception ex)
{
objLog.ErrorLogFile("NotificationRepository_RemoveKamTicket", ex.Message, path, errorlogtf);
throw ex;
}
}
#endregion
}
}