351 lines
12 KiB
C#
351 lines
12 KiB
C#
namespace VECV_WebApi.Controllers.Sync
|
|
{
|
|
using ExcelHelper;
|
|
#region Namespaces
|
|
|
|
using LoggingHelper;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
using RestSharp;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Data;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
using System.Text.RegularExpressions;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Mvc;
|
|
using System.Web.Script.Serialization;
|
|
using VECV_WebApi.Models.EmailServices;
|
|
using VECV_WebApi.Models.Sync;
|
|
using VECV_WebApi.Models.Ticket;
|
|
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// This controller contain apis releted to offline syncing
|
|
/// </summary>
|
|
public class SyncController : 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"]);
|
|
|
|
/// <summary>
|
|
/// making Global Repository object available to this class
|
|
/// </summary>
|
|
GlobalRepository objGlobalRepository = new GlobalRepository("");
|
|
|
|
/// <summary>
|
|
/// making Sync Repository object available to this class
|
|
/// </summary>
|
|
SyncRepository objSyncRepository;
|
|
|
|
/// <summary>
|
|
/// making the Database connection string available to this class
|
|
/// </summary>
|
|
private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString();
|
|
|
|
#endregion
|
|
|
|
|
|
#region APIs
|
|
|
|
/// <summary>
|
|
/// To get synced open tickets details device alias wise
|
|
/// </summary>
|
|
/// <param name="model">open ticket sync info</param>
|
|
/// <returns>synced open tickets details device alias wise</returns>
|
|
public List<SyncOpenModel> Post([FromBody] SyncOpenModel model)
|
|
{
|
|
SyncOpenModel objModel = new SyncOpenModel();
|
|
List<SyncOpenModel> objList = new List<SyncOpenModel>();
|
|
try
|
|
{
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
objList = objSyncRepository.GetSyncOpenTicketDetail(model);
|
|
|
|
return objList;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("GetSyncOpenTicketDetail_Controller", Ex.Message, path, errorlogtf);
|
|
|
|
objList.Add(new SyncOpenModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
});
|
|
return objList;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// To get close tickets detail device alias wise
|
|
/// </summary>
|
|
/// <param name="Close">extra param to identify the api</param>
|
|
/// <param name="model">close ticket sync info</param>
|
|
/// <returns>close tickets detail device alias wise</returns>
|
|
public List<SyncCloseModel> Post([FromUri] string Close, [FromBody] SyncCloseModel model)
|
|
{
|
|
|
|
SyncCloseModel objModel = new SyncCloseModel();
|
|
List<SyncCloseModel> objList = new List<SyncCloseModel>();
|
|
try
|
|
{
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
objList = objSyncRepository.GetSyncCloseTicketDetail(model);
|
|
return objList;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("GetSyncCloseTicketDetail_Controller", Ex.Message, path, errorlogtf);
|
|
|
|
objList.Add(new SyncCloseModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
});
|
|
|
|
return objList;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// To get all tickets detail device alias wise
|
|
/// </summary>
|
|
/// <param name="Sync">extra param to identify the api</param>
|
|
/// <param name="model">open + close ticket sync info</param>
|
|
/// <returns>all tickets detail device alias wise</returns>
|
|
public List<SyncModel> Post([FromUri] string Sync, [FromBody] SyncModel model)
|
|
{
|
|
|
|
SyncModel objModel = new SyncModel();
|
|
List<SyncModel> objList = new List<SyncModel>();
|
|
|
|
try
|
|
{
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
objList = objSyncRepository.GetSyncTicketDetail(model);
|
|
|
|
return objList;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("GetSyncTicketDetail_Controller", Ex.Message, path, errorlogtf);
|
|
|
|
objList.Add(new SyncModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
|
|
});
|
|
return objList;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// To get dealer open/close tickets for syncing
|
|
/// </summary>
|
|
/// <param name="Sync">extra param to identify the api</param>
|
|
/// <param name="Dealer">extra param to identify the api</param>
|
|
/// <param name="model">open + close ticket sync info</param>
|
|
/// <returns>all tickets detail device alias wise</returns>
|
|
public List<SyncModel> Post([FromUri] string Sync, [FromUri] string Dealer, [FromBody] SyncModel model)
|
|
{
|
|
SyncModel objModel = new SyncModel();
|
|
List<SyncModel> objList = new List<SyncModel>();
|
|
|
|
try
|
|
{
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
objList = objSyncRepository.GetSyncTicketDetail_Dealer(model);
|
|
|
|
return objList;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objList.Add(new SyncModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
|
|
});
|
|
return objList;
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// To get KAM open/close tickets for syncing
|
|
/// </summary>
|
|
/// <param name="Sync">extra param to identify th4444e api</param>
|
|
/// <param name="model">open + close ticket sync info</param>
|
|
/// <returns>all tickets detail device alias wise</returns>
|
|
public List<SyncModel> Post([FromUri] string Sync, [FromUri] string Kam, [FromUri] string Customer, [FromBody] SyncModel model)
|
|
{
|
|
SyncModel objModel = new SyncModel();
|
|
List<SyncModel> objList = new List<SyncModel>();
|
|
|
|
try
|
|
{
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
objList = objSyncRepository.GetSyncTicketDetail_Kam(model);
|
|
|
|
return objList;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objList.Add(new SyncModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
|
|
});
|
|
return objList;
|
|
}
|
|
}
|
|
|
|
public TicketStatusModel Get([FromUri] string TicketId, [FromUri] string strTicketStatus )
|
|
{
|
|
TicketStatusModel objticket = new TicketStatusModel();
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
|
|
objticket = objSyncRepository.GetSyncTicketDetail(TicketId, strTicketStatus);
|
|
|
|
return objticket;
|
|
|
|
}
|
|
public List<DTCCodeMaster> Get([FromUri] string dtccodes)
|
|
{
|
|
List<DTCCodeMaster> objDTCcode = new List<DTCCodeMaster>();
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
string[] strings = dtccodes.Split(',');
|
|
// int[] ints = Array.ConvertAll(strings, s => int.Parse(s));
|
|
objDTCcode = objSyncRepository.GetAllDtcDescriptionListDataSet(strings);
|
|
return objDTCcode;
|
|
}
|
|
|
|
|
|
|
|
public TechModel Post([FromUri] string Sync, [FromUri] string techinician, [FromUri] string techinician_number, [FromUri] string Customer, [FromBody] TechModel model)
|
|
{
|
|
TechModel objModel = new TechModel();
|
|
List<SyncModel> objList = new List<SyncModel>();
|
|
string strmsg = "";
|
|
// objLog.ErrorLogFile("Sync Mobile number",model.Tech_Number, path, errorlogtf);
|
|
|
|
string istrue = "";
|
|
try
|
|
{
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
bool isValid = IsValidMobileNumber(model.Tech_Number);
|
|
if (isValid == true)
|
|
{
|
|
if (model.Tech_Number.Length == 10)
|
|
{
|
|
istrue = "true";
|
|
|
|
}
|
|
else
|
|
{
|
|
istrue = "false";
|
|
strmsg = "Please enter 10 digit mobile number";
|
|
}
|
|
}
|
|
else
|
|
{
|
|
strmsg = "Please enter 10 digit mobile number";
|
|
istrue = "false";
|
|
}
|
|
if (istrue == "false")
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
strmsg = objSyncRepository.insertTechnicianNumber(model.TicketId, model.Tech_Number);
|
|
}
|
|
objModel.Message = strmsg;
|
|
objModel.TicketId = model.TicketId;
|
|
objModel.Tech_Number = model.Tech_Number;
|
|
|
|
|
|
return objModel;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objLog.ErrorLogFile("insertTechnicianNumber", Ex.Message, path, errorlogtf);
|
|
objList.Add(new SyncModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
|
|
|
|
});
|
|
}
|
|
|
|
|
|
|
|
return objModel;
|
|
|
|
}
|
|
|
|
public VECV_WebApi.Models.Sync.CustomerOpenTicketDetail Post([FromUri] string Sync, [FromUri] string tikcetdetails, [FromUri] string latest, [FromUri] string ticketid, [FromUri] string getdetails, [FromBody] SyncModel model)
|
|
{
|
|
// SyncModel objModel = new SyncModel();
|
|
// List<SyncModel> objList = new List<SyncModel>();
|
|
VECV_WebApi.Models.Sync.CustomerOpenTicketDetail objModel = new VECV_WebApi.Models.Sync.CustomerOpenTicketDetail();
|
|
|
|
try
|
|
{
|
|
objSyncRepository = new SyncRepository(_connStr);
|
|
|
|
objModel = objSyncRepository.getTicketDetailLatestUpdate(model);
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objLog.ErrorLogFile("insertTechnicianNumber", Ex.Message, path, errorlogtf);
|
|
|
|
}
|
|
return objModel;
|
|
|
|
}
|
|
static bool IsValidMobileNumber(string number)
|
|
{
|
|
string pattern = @"^\+?[0-9\s\-]*$"; // Adjust the regex pattern to match your requirements
|
|
Regex regex = new Regex(pattern);
|
|
return regex.IsMatch(number);
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|
|
|