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 /// /// making object of LoggingUtility class available to this class /// LoggingUtility objLog = new LoggingUtility(); /// /// making the data-log file path available to this class /// string path = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]); /// /// making error log file path available to this class /// string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]); /// /// making the Database connection string available to this class /// private string _connStr; #endregion #region Contructors /// /// Default constructor intialize connection string of vecv database /// public NotificationRepository(string connString) { this._connStr = connString; } /// /// making Authentication Repository object available to this class /// AuthenticationRepository objAuthorization; #endregion #region API Methods /// /// To get KAM notifications /// /// notification input info /// status and open ticket detail of dealer public NotificationOutputModel GetKamNotification(NotificationInputModel model) { NotificationOutputModel objModel = new NotificationOutputModel(); List objList = new List(); 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("_temp_ticket_id").ToString(), NotificationId = s.Field("_notification_id").ToString(), KamName = s.Field("_kam_name"), VehicleRegNo = s.Field("_vehicle_registration"), NotificationTime = s.Field("_notification_time") != null ? Convert.ToDateTime(s.Field("_notification_time")).AddMinutes(model.UtcMinute).ToString(ConfigurationManager.AppSettings["DateTimeFormat"]) : Convert.ToDateTime(s.Field("estimated_time_for_job_completion_submit_time")).ToString(ConfigurationManager.AppSettings["DateTimeFormat"]), MobileNo1 = s.Field("_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; } } /// /// To delete KAM notifications /// /// notification input info /// status and open ticket detail of dealer public NotificationOutputModel DeleteKamNotification(NotificationInputModel model) { NotificationOutputModel objModel = new NotificationOutputModel(); List objList = new List(); 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 /// /// To get user detail user name wise /// /// Represent object of usermodel class contain user name /// status and user detail user name wise 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; } } /// /// To get user detail user name wise /// /// Represent object of usermodel class /// /// user name /// status and user detail user name wise 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 } }