259 lines
8.7 KiB
C#
259 lines
8.7 KiB
C#
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
|
|
|
|
/// <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 data log file path available to this class
|
|
/// </summary>
|
|
string logtf = (ConfigurationManager.AppSettings["Log"]);
|
|
|
|
/// <summary>
|
|
/// making error log file path available to this class
|
|
/// </summary>
|
|
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
|
|
|
|
string _appName = (ConfigurationManager.AppSettings["ApplicationName"]);
|
|
|
|
/// <summary>
|
|
/// making the Database connection string available to this class
|
|
/// </summary>
|
|
private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString();
|
|
|
|
/// <summary>
|
|
/// making Global Repository object available to this class
|
|
/// </summary>
|
|
/// GlobalRepository objGlobalRepository;
|
|
|
|
/// <summary>
|
|
/// making Customer Repository object available to this class
|
|
/// </summary>
|
|
CustomerRepository objCustomerRepository;
|
|
|
|
/// <summary>
|
|
/// making Ticket Repository object available to this class
|
|
/// </summary>
|
|
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<EscalationLevel> oEscalationLevelList = new List<EscalationLevel>();
|
|
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<string>("dealer_id"),
|
|
ManagerName = s.Field<string>("manager_name"),
|
|
ManagerLevel = s.Field<string>("manager_level"),
|
|
ManagerPhoneNo = s.Field<string>("phones"),
|
|
VehicleType = s.Field<string>("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;
|
|
}
|
|
}
|
|
}
|