EOS-WebAPI/Models/Notification/NotificationRepository.cs
Nidhi Bhargava d0ac8a7790 Code Commit
2025-09-04 17:30:22 +05:30

300 lines
13 KiB
C#

using DBHelper;
using LoggingHelper;
using Npgsql;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using VECV_WebApi.Models.Authorization;
namespace VECV_WebApi.Models.Notification
{
public class NotificationRepository
{
#region Global Variables
/// <summary>
/// making object of LoggingUtility class available to this class
/// </summary>
LoggingUtility objLog = new LoggingUtility();
/// <summary>
/// making the data-log file path available to this class
/// </summary>
string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
/// <summary>
/// making error log file path available to this class
/// </summary>
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
/// <summary>
/// making the Database connection string available to this class
/// </summary>
private string _connStr;
#endregion
#region Contructors
/// <summary>
/// Default constructor intialize connection string of vecv database
/// </summary>
public NotificationRepository(string connString)
{
this._connStr = connString;
}
/// <summary>
/// making Authentication Repository object available to this class
/// </summary>
AuthenticationRepository objAuthorization;
#endregion
#region API Methods
/// <summary>
/// To get KAM notifications
/// </summary>
/// <param name="model">notification input info</param>
/// <returns>status and open ticket detail of dealer</returns>
public NotificationOutputModel GetKamNotification(NotificationInputModel model)
{
NotificationOutputModel objModel = new NotificationOutputModel();
List<NotificationModel> objList = new List<NotificationModel>();
try
{
DataSet ds = new DataSet();
objAuthorization = new AuthenticationRepository();
if (objAuthorization.AuthenticateDevice(model.Token))
{
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_kam_ticket_notifications"]);
if (ds.Tables[0].Rows.Count > 0)
{
objList = ds.Tables[0].AsEnumerable().Select(s => new NotificationModel
{
KamTicketId = s.Field<Int32>("_temp_ticket_id").ToString(),
NotificationId = s.Field<Int32>("_notification_id").ToString(),
KamName = s.Field<string>("_kam_name"),
VehicleRegNo = s.Field<string>("_vehicle_registration"),
NotificationTime = s.Field<DateTime?>("_notification_time") != null ? Convert.ToDateTime(s.Field<DateTime?>("_notification_time")).AddMinutes(model.UtcMinute).ToString(ConfigurationManager.AppSettings["DateTimeFormat"]) : Convert.ToDateTime(s.Field<DateTime?>("estimated_time_for_job_completion_submit_time")).ToString(ConfigurationManager.AppSettings["DateTimeFormat"]),
MobileNo1 = s.Field<string>("_mobile_number_1")
}).ToList();
}
objModel.Status = "1";
objModel.NotificationList = objList;
}
else
{
objModel.Status = "0";
objModel.Message = "Not Authorized";
}
return objModel;
}
catch (Exception Ex)
{
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("GetKamNotification", Ex.Message, path, errorlogtf);
return objModel;
}
}
/// <summary>
/// To delete KAM notifications
/// </summary>
/// <param name="model">notification input info</param>
/// <returns>status and open ticket detail of dealer</returns>
public NotificationOutputModel DeleteKamNotification(NotificationInputModel model)
{
NotificationOutputModel objModel = new NotificationOutputModel();
List<NotificationModel> objList = new List<NotificationModel>();
try
{
DataSet ds = new DataSet();
objAuthorization = new AuthenticationRepository();
if (objAuthorization.AuthenticateDevice(model.Token))
{
NpgsqlParameter[] nSqlParam = new NpgsqlParameter[1];
nSqlParam[0] = new NpgsqlParameter("innotification_id", model.NotificationId);
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_close_open_kam_notifications"], nSqlParam);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0][0].ToString() == "1")
{
objModel.Message = "Success";
objModel.Status = "1";
}
else
{
objModel.Message = "Failure";
objModel.Status = "0";
}
}
}
else
{
objModel.Status = "0";
objModel.Message = "Not Authorized";
}
return objModel;
}
catch (Exception Ex)
{
objModel.Status = "0";
objModel.Message = Ex.Message;
objLog.ErrorLogFile("DeleteKamNotification", Ex.Message, path, errorlogtf);
return objModel;
}
}
// Added by priya 20-04-2022
/// <summary>
/// To get user detail user name wise
/// </summary>
/// <param name="model">Represent object of usermodel class contain user name</param>
/// <returns>status and user detail user name wise</returns>
public TicketWhatsupAPIModel GetTicketStatusByTicketId(string TicketId)
{
TicketWhatsupAPIModel objticketModel = new TicketWhatsupAPIModel();
try
{
DataSet ds = new DataSet();
objLog.ErrorLogFile("TicketId", TicketId, path, errorlogtf);
if (TicketId.Contains("TICKETID") == true)
{
NpgsqlParameter[] nSqlParam1 = new NpgsqlParameter[2];
nSqlParam1[0] = new NpgsqlParameter("inticket_id", TicketId);
nSqlParam1[1] = new NpgsqlParameter("invehicle_reg", null);
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_TicketStatus_for_whatsup_api_by_Id"], nSqlParam1);
}
else
{
NpgsqlParameter[] nSqlParam1 = new NpgsqlParameter[2];
nSqlParam1[0] = new NpgsqlParameter("inticket_id", TicketId);
nSqlParam1[1] = new NpgsqlParameter("invehicle_reg", null);
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_TicketStatus_for_whatsup_api"], nSqlParam1);
}
if (ds.Tables[0].Rows[0]["TicketId"].ToString().Trim() != null && ds.Tables[0].Rows[0]["TicketId"].ToString().Trim() != "")
{
//added on 19-11-2020 start
objticketModel.TicketId = ds.Tables[0].Rows[0]["TicketId"].ToString();
objticketModel.TicketIdAlias = ds.Tables[0].Rows[0]["_ticket_id_alias"].ToString();
objticketModel.VehicleRegisterNumber = ds.Tables[0].Rows[0]["vehicle_registration_number"].ToString();
objticketModel.WorkshopName = ds.Tables[0].Rows[0]["WorkshopName"].ToString();
objticketModel.WorksManagerName = ds.Tables[0].Rows[0]["WorksManagerName"].ToString();
objticketModel.WorksManagerContactNo = ds.Tables[0].Rows[0]["wm_contact_no"].ToString();
objticketModel.TechnicianContactNo = ds.Tables[0].Rows[0]["service_engineer_contact_number"].ToString();
objticketModel.TechnicianName = ds.Tables[0].Rows[0]["dealer_or_service_engg"].ToString();
objticketModel.TicketActivityStatus = ds.Tables[0].Rows[0]["ticket_activity_status"].ToString();
objticketModel.TicketStatusAlias = ds.Tables[0].Rows[0]["ticket_status_alias"].ToString();
}
return objticketModel;
}
catch (Exception Ex)
{
// write error log into file
// objticketModel.Status = "0";
// objticketModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message;
objLog.ErrorLogFile("GetTicketStatusByTicketId usp_get_TicketStatus_for_whatsup_api", Ex.Message, path, errorlogtf);
return objticketModel;
}
}
public string GetTicketStatusOpenCloseByTicketId(string TicketId)
{
string ticketstatus = "";
try
{
DataSet ds = new DataSet();
NpgsqlParameter[] nSqlParam1 = new NpgsqlParameter[1];
nSqlParam1[0] = new NpgsqlParameter("inticket_id", TicketId);
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_TicketStatus_By_TicketId"], nSqlParam1);
if (ds.Tables[0].Rows[0]["ticket_status_alias"].ToString().Trim() != null && ds.Tables[0].Rows[0]["ticket_status_alias"].ToString().Trim() != "")
{
ticketstatus = ds.Tables[0].Rows[0]["ticket_status_alias"].ToString();
}
return ticketstatus;
}
catch (Exception Ex)
{
// write error log into file
// objticketModel.Status = "0";
// objticketModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message;
objLog.ErrorLogFile("GetTicketStatusOpenCloseByTicketId", Ex.Message, path, errorlogtf);
return ticketstatus;
}
}
/// <summary>
/// To get user detail user name wise
/// </summary>
/// <param name="model">Represent object of usermodel class
///
/// user name</param>
/// <returns>status and user detail user name wise</returns>
public TicketWhatsupAPIModel GetTicketStatusByRegistrationNumber(string VehicleRegisterNumber)
{
TicketWhatsupAPIModel objticketModel = new TicketWhatsupAPIModel();
try
{
DataSet ds = new DataSet();
NpgsqlParameter[] nSqlParam1 = new NpgsqlParameter[1];
// nSqlParam1[0] = new NpgsqlParameter("inticket_id", null);
nSqlParam1[0] = new NpgsqlParameter("invehicle_reg", VehicleRegisterNumber);
ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_TicketStatus_for_whatsup_api_byRegNo"], nSqlParam1);
if (ds.Tables[0].Rows[0]["TicketId"].ToString().Trim() != null && ds.Tables[0].Rows[0]["TicketId"].ToString().Trim() != "")
{
//added on 19-11-2020 start
objticketModel.TicketId = ds.Tables[0].Rows[0]["TicketId"].ToString();
objticketModel.TicketIdAlias = ds.Tables[0].Rows[0]["_ticket_id_alias"].ToString();
objticketModel.VehicleRegisterNumber = ds.Tables[0].Rows[0]["vehicle_registration_number"].ToString();
objticketModel.WorkshopName = ds.Tables[0].Rows[0]["WorkshopName"].ToString();
objticketModel.WorksManagerName = ds.Tables[0].Rows[0]["WorksManagerName"].ToString();
objticketModel.WorksManagerContactNo = ds.Tables[0].Rows[0]["wm_contact_no"].ToString();
objticketModel.TechnicianContactNo = ds.Tables[0].Rows[0]["service_engineer_contact_number"].ToString();
objticketModel.TechnicianName = ds.Tables[0].Rows[0]["dealer_or_service_engg"].ToString();
objticketModel.TicketActivityStatus = ds.Tables[0].Rows[0]["ticket_activity_status"].ToString();
objticketModel.TicketStatusAlias = ds.Tables[0].Rows[0]["ticket_status_alias"].ToString();
}
return objticketModel;
}
catch (Exception Ex)
{
// write error log into file
// objticketModel.Status = "0";
// objticketModel.Message = ConfigurationManager.AppSettings["PwdErrorMsg"].ToString() + Ex.Message;
objLog.ErrorLogFile("GetTicketStatusByRegistrationNumber", Ex.Message, path, errorlogtf);
return objticketModel;
}
}
#endregion
}
}