using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Web.Http; namespace VECV_WebApi.Controllers.Global { using DBHelper; using ExcelHelper; #region Namespaces using LoggingHelper; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Npgsql; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Globalization; using System.Linq; using System.Net; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; using System.Web; using System.Web.Http; using System.Web.Mvc; using VECV_WebApi.Common; using VECV_WebApi.Models.Customer; using VECV_WebApi.Models.EmailServices; using VECV_WebApi.Models.Ticket; using VECV_WebApi.Models.Vehicle; #endregion public class SMSController : ApiController { #region Global Variable /// /// 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 data log file path available to this class /// string logtf = (ConfigurationManager.AppSettings["Log"]); /// /// making error log file path available to this class /// string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]); string _appName = (ConfigurationManager.AppSettings["ApplicationName"]); /// /// making the Database connection string available to this class /// private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString(); /// /// making Global Repository object available to this class /// /// GlobalRepository objGlobalRepository; /// /// making Customer Repository object available to this class /// CustomerRepository objCustomerRepository; /// /// making Ticket Repository object available to this class /// TicketRepository objTicketRepository; #endregion public string Post([FromBody] SMSApiResponse model) { string stsuccess = ""; // write data log into file GlobalRepository objGlobalRepository = new GlobalRepository(_connStr); try { string msgownerSMSTicket = System.Web.Configuration.WebConfigurationManager.AppSettings["msgOtpSMSTicket"].ToString(); string url = System.Web.Configuration.WebConfigurationManager.AppSettings["SmsUrl"].ToString(); msgownerSMSTicket = string.Format(msgownerSMSTicket, model.ticket_id, model.OTP.ToString() ); string CustomerSms = string.Format(url,model.Customer_name, msgownerSMSTicket); objLog.ErrorLogFile("owner otp", CustomerSms, path, errorlogtf); objGlobalRepository.SendMessage(CustomerSms); stsuccess = "success"; return stsuccess; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("case mamagement api", Ex.Message, path, errorlogtf); } return stsuccess; } public string Post(string otp, string getotp, [FromBody] InsertOpenTicket model) { string stsuccess = ""; // write data log into file TicketRepository objTicketRepository = new TicketRepository(_connStr); stsuccess = objTicketRepository.getOTP(model); return stsuccess; } public string Post(string sendsms,[FromBody] SMSApiResponse model) { string stsuccess = ""; // write data log into file GlobalRepository objGlobalRepository = new GlobalRepository(_connStr); try { DataSet ds = new DataSet(); string msgownerSMSTicket = System.Web.Configuration.WebConfigurationManager.AppSettings["msgDealerSMSTicket"].ToString(); string url = System.Web.Configuration.WebConfigurationManager.AppSettings["SmsUrl"].ToString(); NpgsqlParameter[] nSqlParam1 = new NpgsqlParameter[2]; nSqlParam1[0] = new NpgsqlParameter("inticket_id", model.ticket_id); nSqlParam1[1] = new NpgsqlParameter("invehicle_reg", null); ds = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_contact_details_for_sms_api"], nSqlParam1); // ds.Tables[0].Rows[0]["_dealer_dealer_name"].ToString() //ds.Tables[0].Rows[0]["_dealer_contact_number1"].ToString() // ds.Tables[0].Rows[0]["WM_contact_no"].ToString() if (model.ModelNumber == null) { if (model.ProductVariant == null) { model.VehicleType = model.VehicleType; } else { if (model.ProductVariant.ToLower() == "electric") { model.VehicleType = model.VehicleType + " EV"; } } } else { string str = model.ModelNumber.ToLower(); string substring = "titan"; if (str.Contains(substring)) { if (model.ProductVariant == null) { model.VehicleType = model.VehicleType + " TITAN"; } else { if (model.ProductVariant.ToLower() == "electric") { model.VehicleType = model.VehicleType + " TITAN" + " EV"; } } } } List oEscalationLevelList = new List(); DataSet escalationLevelDataset = new DataSet(); NpgsqlParameter[] nSqlParam = new NpgsqlParameter[2]; nSqlParam[0] = new NpgsqlParameter("in_dealer_id", model.Dealer_code); nSqlParam[1] = new NpgsqlParameter("in_vehicle_type", model.VehicleType); escalationLevelDataset = NpgSqlHelper.ExecuteDataset(_connStr, CommandType.StoredProcedure, ConfigurationManager.AppSettings["usp_get_escalation_level_by_dealer_id_vehicle_type"], nSqlParam); if (escalationLevelDataset.Tables[0].Rows.Count > 0) { oEscalationLevelList = escalationLevelDataset.Tables[0].AsEnumerable().Select(s => new EscalationLevel { DelaerId = s.Field("dealer_id"), ManagerName = s.Field("manager_name"), ManagerLevel = s.Field("manager_level"), ManagerPhoneNo = s.Field("phones"), VehicleType = s.Field("van_type") }).ToList(); } string sitename = ""; string wmname = ""; for (int i = 0; i < oEscalationLevelList.Count; i++) { if (oEscalationLevelList[i].ManagerLevel == "EOS Site Incharge") { model.EOSSiteName = oEscalationLevelList[i].ManagerName; model.EOSSiteNo = oEscalationLevelList[i].ManagerPhoneNo; sitename = model.EOSSiteName + "/" + model.EOSSiteNo; } if (oEscalationLevelList[i].ManagerLevel.ToString() == "WM") { if (model.EOSSiteName == "") { sitename = model.WMName; wmname = model.WmNo; ; } else { model.WMName = oEscalationLevelList[i].ManagerName; model.WmNo = oEscalationLevelList[i].ManagerPhoneNo; wmname = model.WMName + "/" + model.WmNo; } } } model.DealerName = ds.Tables[0].Rows[0]["dealer_dealer_name"].ToString(); model.DealerNo = ds.Tables[0].Rows[0]["_dealer_contact_number1"].ToString(); //ds.Tables[0].Rows[0]["_dealer_contact_number1"].ToString() msgownerSMSTicket = string.Format(msgownerSMSTicket, sitename, wmname, model.DealerName); string CustomerSms = string.Format(url, model.Customer_name, msgownerSMSTicket); objGlobalRepository.SendMessage(CustomerSms); objLog.ErrorLogFile("GetDealerStateCityWise_Controller", CustomerSms, path, errorlogtf); stsuccess = "success"; return stsuccess; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("case mamagement api", Ex.Message, path, errorlogtf); } return stsuccess; } } }