320 lines
12 KiB
C#
320 lines
12 KiB
C#
namespace VECV_WebApi.Controllers.Ticket
|
|
{
|
|
using ExcelHelper;
|
|
#region Namespaces
|
|
|
|
using LoggingHelper;
|
|
using Newtonsoft.Json;
|
|
using Newtonsoft.Json.Linq;
|
|
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
|
|
|
|
/// <summary>
|
|
/// This controller
|
|
/// ticket related api
|
|
/// </summary>
|
|
public class GlobalAPIController : 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
|
|
|
|
|
|
#region APIs
|
|
|
|
public ApiResponse Post([FromBody] APIValueModel model)
|
|
{
|
|
// write data log into file
|
|
ApiResponse objApiResponse = new ApiResponse();
|
|
try
|
|
{
|
|
|
|
TicketRepository objTicket = new TicketRepository(_connStr);
|
|
objApiResponse = objTicket.GetCaseManagementDetails(model.ticket_Id);
|
|
return objApiResponse;
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("case mamagement api", Ex.Message, path, errorlogtf);
|
|
|
|
|
|
}
|
|
return objApiResponse;
|
|
}
|
|
|
|
public bool Post([FromUri] string sendEmail, [FromBody] APIValueModel model)
|
|
{
|
|
bool issend = false;
|
|
TicketRepository objTicket = new TicketRepository(_connStr);
|
|
|
|
try
|
|
{
|
|
issend = objTicket.SendEmailMultipleUserModelMatrix(model);
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("send model email", Ex.Message, path, errorlogtf);
|
|
|
|
|
|
}
|
|
return issend;
|
|
|
|
}
|
|
public Int64 Post([FromUri] string mqCount, [FromUri] string getvalue, [FromBody] TicketRequestModel model)
|
|
{
|
|
Int64 mqCountvalue = 0;
|
|
TicketRepository objTicketRepository = new TicketRepository(_connStr);
|
|
|
|
try
|
|
{
|
|
mqCountvalue = objTicketRepository.GetMqCount(model);
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("send model email", Ex.Message, path, errorlogtf);
|
|
|
|
|
|
}
|
|
return mqCountvalue;
|
|
|
|
}
|
|
|
|
public string Post([FromUri] string VahanAPI, [FromUri] string getChassisNo, [FromUri] string getValue, [FromUri] string getvalue1, [FromBody] TicketListOpenTickets model)
|
|
{
|
|
string strchassisNo = "";
|
|
TicketRepository objTicketRepository = new TicketRepository(_connStr);
|
|
|
|
try
|
|
{
|
|
strchassisNo = objTicketRepository.DetailFormVAHANApi(model.VehicleRegistrationNo);
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("send model email", Ex.Message, path, errorlogtf);
|
|
|
|
|
|
}
|
|
return strchassisNo;
|
|
|
|
}
|
|
|
|
public string Post([FromUri] string VahanDetailsReport, [FromUri] string isDownload, [FromUri] string report, [FromUri] string VahanAPI, [FromUri] string getChassisNo, [FromUri] string getValue, [FromUri] string getvalue1, [FromBody] ReportRequestModel model)
|
|
{
|
|
string strchassisNo = "";
|
|
TicketRepository objTicketRepository = new TicketRepository(_connStr);
|
|
List<VAHANAPI> objVAHANAPI = new List<VAHANAPI>();
|
|
ReportRequestModel ObjModel = new ReportRequestModel();
|
|
ObjModel.VAHANAPIReport = objTicketRepository.VahanDetailReport(model);
|
|
string fileName = null;
|
|
bool isCreated = false;
|
|
List<VAHANAPI> oList = new List<VAHANAPI>();
|
|
oList = ObjModel.VAHANAPIReport;
|
|
try
|
|
{
|
|
DataTable OpenTicketTable = oList.ToDataTable();
|
|
Int32 OpenTicketTableColumnCount = OpenTicketTable.Columns.Count - 1;
|
|
DataSet ds = new DataSet();
|
|
ds.Tables.Add(OpenTicketTable);
|
|
|
|
|
|
ds.Tables[0].Columns[0].ColumnName = "Chassis Number";
|
|
ds.Tables[0].Columns[1].ColumnName = "vehicle Manufacturer Name";
|
|
ds.Tables[0].Columns[2].ColumnName = "Model";
|
|
ds.Tables[0].Columns[3].ColumnName = "Norms Type";
|
|
ds.Tables[0].Columns[4].ColumnName = "type";
|
|
ds.Tables[0].Columns[5].ColumnName = "Owner";
|
|
ds.Tables[0].Columns[6].ColumnName = "Ticket Creation Time";
|
|
|
|
ds.Tables[0].Columns[7].ColumnName = "Regitration Number";
|
|
|
|
|
|
ExcelUtility objExcelUtility = new ExcelHelper.ExcelUtility();
|
|
List<WorkbookMappingModel> workbokkMapping = new List<WorkbookMappingModel>();
|
|
string _excelExportPathOnServer = ConfigurationManager.AppSettings["excelExportPathOnServer"].ToString();
|
|
fileName = "VahanAPIReport_" + DateTime.Now.ToString("ddMMMyyyyhhmmss") + ".xlsx";
|
|
workbokkMapping.Add(new WorkbookMappingModel { DataTableName = ds.Tables[0].TableName, WorkSheetName = "Open Report", StartColumnName = "A", StartRowNumber = 2, WorkSheetNumber = 1, AutoFit = false });
|
|
string templatePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["OpenTicketReportTemplate"].ToString());
|
|
string _exportLocation = ConfigurationManager.AppSettings["excelExportPath"].ToString();
|
|
string pathToExcelFile = _exportLocation + fileName;
|
|
string SaveCsvAs = HttpContext.Current.Server.MapPath(_excelExportPathOnServer + fileName);
|
|
isCreated = CreateExcelFile.CreateExcelDocument(ds, SaveCsvAs);
|
|
if (isCreated == true) { return _exportLocation + fileName; }
|
|
else { return "error"; }
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("VahanDetailsErrorReport", Ex.Message, path, errorlogtf);
|
|
throw Ex;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
public string Post([FromUri] string VahanDetailsErrorReport, [FromUri] string isDownload, [FromUri] string report, [FromUri] string reportdownload, [FromUri] string VahanAPI, [FromUri] string getChassisNo, [FromUri] string getValue, [FromUri] string getvalue1, [FromBody] ReportRequestModel model)
|
|
{
|
|
string strchassisNo = "";
|
|
TicketRepository objTicketRepository = new TicketRepository(_connStr);
|
|
List<VAHANAPIError> objVAHANAPI = new List<VAHANAPIError>();
|
|
ReportRequestModel ObjModel = new ReportRequestModel();
|
|
|
|
try
|
|
{
|
|
|
|
ObjModel.VAHANAPIErrorReport = objTicketRepository.VahanDetailErrorReport(model);
|
|
List<VAHANAPIError> oList = new List<VAHANAPIError>();
|
|
string fileName = null;
|
|
bool isCreated = false;
|
|
oList = ObjModel.VAHANAPIErrorReport;
|
|
|
|
DataTable OpenTicketTable = oList.ToDataTable();
|
|
Int32 OpenTicketTableColumnCount = OpenTicketTable.Columns.Count - 1;
|
|
DataSet ds = new DataSet();
|
|
ds.Tables.Add(OpenTicketTable);
|
|
|
|
ds.Tables[0].Columns[0].ColumnName = "Message";
|
|
ds.Tables[0].Columns[1].ColumnName = "Status";
|
|
ds.Tables[0].Columns[2].ColumnName = "Reason";
|
|
ds.Tables[0].Columns[3].ColumnName = "Fuel Type";
|
|
ds.Tables[0].Columns[4].ColumnName = "Status Code";
|
|
ds.Tables[0].Columns[5].ColumnName = "Regitration Number";
|
|
ds.Tables[0].Columns[6].ColumnName = "Ticket Creation Time";
|
|
|
|
ExcelUtility objExcelUtility = new ExcelHelper.ExcelUtility();
|
|
List<WorkbookMappingModel> workbokkMapping = new List<WorkbookMappingModel>();
|
|
string _excelExportPathOnServer = ConfigurationManager.AppSettings["excelExportPathOnServer"].ToString();
|
|
fileName = "VahanErrorReport_" + DateTime.Now.ToString("ddMMMyyyyhhmmss") + ".xlsx";
|
|
workbokkMapping.Add(new WorkbookMappingModel { DataTableName = ds.Tables[0].TableName, WorkSheetName = "Open Report", StartColumnName = "A", StartRowNumber = 2, WorkSheetNumber = 1, AutoFit = false });
|
|
string templatePath = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["OpenTicketReportTemplate"].ToString());
|
|
string _exportLocation = ConfigurationManager.AppSettings["excelExportPath"].ToString();
|
|
string pathToExcelFile = _exportLocation + fileName;
|
|
string SaveCsvAs = HttpContext.Current.Server.MapPath(_excelExportPathOnServer + fileName);
|
|
isCreated = CreateExcelFile.CreateExcelDocument(ds, SaveCsvAs);
|
|
if (isCreated == true) { return _exportLocation + fileName; }
|
|
else { return "error"; }
|
|
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("VahanDetailsErrorReport", Ex.Message, path, errorlogtf);
|
|
throw Ex;
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
public string Post([FromUri] string BatteryVoltage, [FromUri] string BatteryVoltagevalue, [FromUri] string getvalue, [FromUri] string getChassisNo, [FromBody] ClodantAPIModel model)
|
|
{
|
|
string batteryVoltage = "";
|
|
GlobalRepository objGlobalRepository = new GlobalRepository(_connStr);
|
|
|
|
try
|
|
{
|
|
/*string devicedetailapi = objGlobalRepository.getDeviceType(model.chassis_no);
|
|
string[] DeviceDetails = devicedetailapi.Split(',');
|
|
|
|
model.device_id = DeviceDetails[1];
|
|
if (DeviceDetails[0] == "TCU 350A")
|
|
{
|
|
model.packet_info = "PER_BS4";
|
|
}
|
|
if (DeviceDetails[0] == "TCU 350C")
|
|
{
|
|
model.packet_info = "PER_BS6";
|
|
}
|
|
*/
|
|
model.device_id = "359207068381993";
|
|
model.packet_info = "PER_BS4";
|
|
Task<string> starval = objGlobalRepository.getBatteryVoltage(model);
|
|
batteryVoltage = starval.Result;
|
|
}
|
|
catch (Exception Ex)
|
|
{
|
|
// write error log into file
|
|
objLog.ErrorLogFile("send model email", Ex.Message, path, errorlogtf);
|
|
|
|
|
|
}
|
|
return batteryVoltage;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
} |