353 lines
14 KiB
C#
353 lines
14 KiB
C#
namespace VECV_WebApi.Controllers.Activity
|
|
{
|
|
#region Namespaces
|
|
using LoggingHelper;
|
|
using Newtonsoft.Json;
|
|
using RestSharp;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Configuration;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Web;
|
|
using System.Web.Http;
|
|
using System.Web.Mvc;
|
|
using System.Web.Script.Serialization;
|
|
using VECV_WebApi.Models.Activity;
|
|
using VECV_WebApi.Models.EmailServices;
|
|
using VECV_WebApi.Models.Ticket;
|
|
using VECV_WebApi.Models.Vehicle;
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// This controller contain APIs releted to actvity on open ticket and close ticket
|
|
/// </summary>
|
|
public class ActivityController : 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 Activity Repository object available to this class
|
|
/// </summary>
|
|
ActivityRepository objActivityRepository;
|
|
|
|
/// <summary>
|
|
/// making the Database connection string available to this class
|
|
/// </summary>
|
|
private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString();
|
|
|
|
#endregion
|
|
|
|
|
|
#region APIs
|
|
|
|
/// <summary>
|
|
/// This method is used for get activity of open ticket detail, ticket id wise
|
|
/// </summary>
|
|
/// <param name="model">Ticket information</param>
|
|
/// <returns>activities of open ticket, ticket id wise</returns>
|
|
public List<OpenTicketActivityTicketWiseModel> Post([FromBody] OpenTicketActivityTicketWiseModel model)
|
|
{
|
|
//write data logs
|
|
|
|
OpenTicketActivityTicketWiseModel objModel = new OpenTicketActivityTicketWiseModel();
|
|
List<OpenTicketActivityTicketWiseModel> objList = new List<OpenTicketActivityTicketWiseModel>();
|
|
try
|
|
{
|
|
objActivityRepository = new ActivityRepository(_connStr);
|
|
objList = objActivityRepository.GetOpenTicketActivityTicketWise(model);
|
|
return objList;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objList.Add(new OpenTicketActivityTicketWiseModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
});
|
|
|
|
//write error log into file
|
|
objLog.ErrorLogFile("GetOpenTicketActivityTicketWise_Controller", Ex.Message, path, errorlogtf);
|
|
return objList;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// This method is used for get activities of close ticket, ticket id wise
|
|
/// </summary>
|
|
/// <param name="model">Ticket Information</param>
|
|
/// <returns>activities of close ticket, ticket id wise</returns>
|
|
public List<CloseTicketActivityTicketWiseModel> Post([FromUri] string Close, [FromBody] CloseTicketActivityTicketWiseModel model)
|
|
{
|
|
// write data log into file
|
|
|
|
CloseTicketActivityTicketWiseModel objModel = new CloseTicketActivityTicketWiseModel();
|
|
List<CloseTicketActivityTicketWiseModel> objList = new List<CloseTicketActivityTicketWiseModel>();
|
|
try
|
|
{
|
|
objActivityRepository = new ActivityRepository(_connStr);
|
|
objList = objActivityRepository.GetCloseTicketActivityTicketWise(model);
|
|
return objList;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objList.Add(new CloseTicketActivityTicketWiseModel
|
|
{
|
|
Status = "0",
|
|
Message = Ex.Message
|
|
});
|
|
return objList;
|
|
}
|
|
}
|
|
|
|
public string Post([FromUri] string preClose,[FromUri] string preClosereason, [FromBody] CloseTicketActivityTicketWiseModel model)
|
|
{
|
|
// write data log into file
|
|
string reasonval = "";
|
|
|
|
try
|
|
{
|
|
objActivityRepository = new ActivityRepository(_connStr);
|
|
reasonval = objActivityRepository.getPreclosureReason(model.TicketId);
|
|
return reasonval;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
reasonval = "error";
|
|
return reasonval;
|
|
}
|
|
}
|
|
public string Get([FromUri] string chassisno, [FromUri] string regno)
|
|
{
|
|
//string chassino = "MC2DALRC0ME001921";
|
|
VehicleRepository objVehicleRepository;
|
|
VehicleModel objModel = new VehicleModel();
|
|
try
|
|
{
|
|
//VehicleRepository objvehicle = new VehicleRepository();
|
|
objVehicleRepository = new VehicleRepository(_connStr);
|
|
//string[] strings = dtccodes.Split(',');
|
|
|
|
VehicleModel model = new VehicleModel();
|
|
model.Id = "";
|
|
model.RegistrationNo = regno;
|
|
// model.Id = null;
|
|
objVehicleRepository = new VehicleRepository(_connStr);
|
|
objModel = objVehicleRepository.GetchessisDetail(model);
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objLog.ErrorLogFile("get chasssi number", Ex.Message, path, errorlogtf);
|
|
}
|
|
return objModel.ChassisNumber;
|
|
}
|
|
//Added by priya 09 feb 2023
|
|
/* public Telematic_Model Get([FromUri] string chassisno)
|
|
{
|
|
Telematic_Model model = new Telematic_Model();
|
|
if (chassisno.Length > 12)
|
|
{
|
|
try
|
|
{
|
|
|
|
string APIRegistrationNo = string.Format(ConfigurationManager.AppSettings["EOSAPI
|
|
"].ToString(), chassisno);
|
|
WebRequest req = WebRequest.Create(APIRegistrationNo);
|
|
req.Method = "GET";
|
|
|
|
ServicePointManager.Expect100Continue = true;
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
|
|
| SecurityProtocolType.Tls11
|
|
| SecurityProtocolType.Tls12
|
|
| SecurityProtocolType.Ssl3
|
|
| (SecurityProtocolType)3072;
|
|
WebResponse webRes = req.GetResponse();
|
|
|
|
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
|
|
if (resp.StatusCode == HttpStatusCode.Created)
|
|
{
|
|
StreamReader ResponseDataStream = new StreamReader(resp.GetResponseStream());
|
|
String res = ResponseDataStream.ReadToEnd();
|
|
JavaScriptSerializer js = new JavaScriptSerializer();
|
|
model = js.Deserialize<Telematic_Model>(res);
|
|
//model.lastdate = model.positionDateTime.ToShortDateString();
|
|
// string jsonified2 = JsonConvert.SerializeObject(model);
|
|
// objLog.AddLogFile("telematic detail", jsonified2, path, errorlogtf);
|
|
// DateTime? dt = null;
|
|
//dt = Convert.ToDateTime(model.positionDateTime);
|
|
string strposteddate = model.positionDateTime.ToShortDateString();
|
|
if (strposteddate == "1/1/0001")
|
|
{
|
|
strposteddate = null;
|
|
}
|
|
else
|
|
{
|
|
strposteddate =model.positionDateTime.ToShortDateString();
|
|
}
|
|
model.lastdate = strposteddate;
|
|
//odometerreading = model.odometer;
|
|
}
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objLog.ErrorLogFile("no telematic details", Ex.Message, path, errorlogtf);
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
*/
|
|
|
|
/// <summary>
|
|
/// Added for new telematics
|
|
/// </summary>
|
|
/// <param name="connected"></param>
|
|
/// <param name="ticketId"></param>
|
|
/// <param name="vehiclestatus"></param>
|
|
/// <returns></returns>
|
|
public Telematic_Model_new Get([FromUri] string chassisno)
|
|
{
|
|
Telematic_Model_new model = new Telematic_Model_new();
|
|
TicketRepository objTicketRepository = new TicketRepository(_connStr);
|
|
var apiurl = "https://apiplatform.vecv.net/volvo-api/getLatestLocation_Volvo/" + chassisno + "/";
|
|
if (chassisno.Length > 12)
|
|
{
|
|
|
|
try
|
|
{
|
|
if (System.Configuration.ConfigurationManager.AppSettings["isProtechAPICall"] != "true")
|
|
{
|
|
//requestVehicleType.AddParameter("chassisno", chassisno);
|
|
var clientVehicleType = new RestClient("https://apiplatform.vecv.net/volvo-api/getLatestLocation_Volvo/" + chassisno + "/");
|
|
clientVehicleType.Timeout = 10000;
|
|
// clientVehicleType.Timeout =-1;
|
|
var requestVehicleType = new RestRequest(Method.GET);
|
|
ServicePointManager.Expect100Continue = true;
|
|
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
|
|
| SecurityProtocolType.Tls11
|
|
| SecurityProtocolType.Tls12
|
|
| SecurityProtocolType.Ssl3
|
|
| (SecurityProtocolType)3072;
|
|
|
|
//requestVehicleType.AddParameter("chassisno", chassisno);
|
|
var username = ConfigurationManager.AppSettings["EOSUSERNAMEFORGETTINGTELEMATICDATA"].ToString();
|
|
var password = ConfigurationManager.AppSettings["EOSPASSWORDFORGETTINGTELEMATICDATA"].ToString();
|
|
|
|
// Add Basic Authentication
|
|
var credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($"{username}:{password}"));
|
|
|
|
// Add Basic Authentication header
|
|
requestVehicleType.AddHeader("Authorization", $"Basic {credentials}");
|
|
requestVehicleType.AddHeader("Content-Type", "application/json");
|
|
IRestResponse responseVehicleType = clientVehicleType.Execute(requestVehicleType);
|
|
Console.WriteLine(responseVehicleType.ResponseStatus);
|
|
|
|
if(responseVehicleType.ResponseStatus.ToString() == "Error")
|
|
{
|
|
|
|
bool isSend = objTicketRepository.emailForError(responseVehicleType.ErrorMessage.ToString(), clientVehicleType.BaseUrl.ToString());
|
|
objLog.ErrorLogFile(clientVehicleType.BaseUrl.ToString(), responseVehicleType.ErrorMessage.ToString(), path, errorlogtf);
|
|
|
|
}
|
|
else {
|
|
if (responseVehicleType.ResponseStatus.ToString() == "TimedOut")
|
|
{
|
|
|
|
bool isSend = objTicketRepository.emailForError(responseVehicleType.ErrorMessage.ToString(), clientVehicleType.BaseUrl.ToString());
|
|
objLog.ErrorLogFile(clientVehicleType.BaseUrl.ToString(), responseVehicleType.ErrorMessage.ToString(), path, errorlogtf);
|
|
|
|
}
|
|
else
|
|
{
|
|
var stringvehcileResult = responseVehicleType.Content.ToString();
|
|
var telematicList = JsonConvert.DeserializeObject<List<Telematic_Model>>(stringvehcileResult);
|
|
|
|
// Get the latitude value
|
|
if (telematicList[0].status.ToLower() == "success")
|
|
{
|
|
model.latitude = telematicList[0].latitude;
|
|
model.longitude = telematicList[0].longitude;
|
|
model.odometer = telematicList[0].odometer;
|
|
model.positionDateTime = telematicList[0].positionDateTime;
|
|
string format = "yyyyMMddHHmmss";
|
|
|
|
// Parse the string to DateTime
|
|
DateTime dateTime = DateTime.ParseExact(model.positionDateTime, format, CultureInfo.InvariantCulture);
|
|
|
|
string strposteddate = dateTime.ToShortDateString();
|
|
if (strposteddate == "1/1/0001")
|
|
{
|
|
strposteddate = null;
|
|
}
|
|
else
|
|
{
|
|
strposteddate = dateTime.ToShortDateString();
|
|
}
|
|
model.lastdate = strposteddate;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
catch (Exception Ex)
|
|
{
|
|
|
|
bool isSend = objTicketRepository.emailForError(Ex.Message, apiurl);
|
|
objLog.ErrorLogFile("no telematic details", Ex.Message, path, errorlogtf);
|
|
}
|
|
}
|
|
return model;
|
|
}
|
|
public string Get([FromUri] string connected, [FromUri] string ticketId, [FromUri] string vehiclestatus)
|
|
{
|
|
//string chassino = "MC2DALRC0ME001921";
|
|
VehicleRepository objVehicleRepository;
|
|
string strmessage = "";
|
|
try
|
|
{
|
|
//VehicleRepository objvehicle = new VehicleRepository();
|
|
objVehicleRepository = new VehicleRepository(_connStr);
|
|
|
|
objVehicleRepository = new VehicleRepository(_connStr);
|
|
strmessage = objVehicleRepository.updateVehicleConnectedFlag(ticketId, vehiclestatus);
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
objLog.ErrorLogFile("vehicle connected or not", Ex.Message, path, errorlogtf);
|
|
}
|
|
return strmessage;
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|