using ExcelHelper; using LoggingHelper; using System; using System.Collections.Generic; using System.Configuration; using System.Data; using System.Linq; using System.Net; using System.Net.Http; using System.Web; using System.Web.Http; using VECV_WebApi.Models.Ticket; namespace VECV_WebApi.Controllers.Ticket { public class PaymentDetailsController : 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"]); /// /// making Ticket Repository object available to this class /// TicketRepository objTicketRepository; /// /// making the Database connection string available to this class /// private string _connStr = ConfigurationManager.ConnectionStrings["Vecv_GoData"].ToString(); #endregion #region APIs /// /// To find ticket detail on device alias. /// /// ticket Payment info /// payment details on ti alias public string Post([FromBody] PaymentDetailsModel model) { try { string strsuccess = ""; List objList = new List(); objTicketRepository = new TicketRepository(_connStr); string strid = objTicketRepository.GetTicketdetailsByTicketId(model.TicketId); model.TicketId_Alias = strid; strsuccess = objTicketRepository.insertPaymentDetails(model); return strsuccess; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("GetTicketDetailOnDeviceAlias_Controller", Ex.Message, path, errorlogtf); throw Ex; } } /// /// To find ticket details based on Device alias. /// /// extra param to identify the api /// ticket info /// ticket details based on Device alias public List Post([FromUri] string getDetails, [FromBody] PaymentDetailsModel model) { List objListfullDetails = new List(); try { // TicketOpenModel objModel = new TicketOpenModel(); objTicketRepository = new TicketRepository(_connStr); objListfullDetails = objTicketRepository.GetPaymentDetailsHistory(model); } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("TicketAcceptOrDecliend_Controller", Ex.Message, path, errorlogtf); throw Ex; } return objListfullDetails; } public string Get(string ticketId) { string status = ""; objTicketRepository = new TicketRepository(_connStr); status = objTicketRepository.GetTicketPrevStatusByTicketId(ticketId); return status; } public string Get(string paymentstatus, string ticketId) { string status = ""; objTicketRepository = new TicketRepository(_connStr); status = objTicketRepository.GetPaymentStatusByTicketId(ticketId); return status; } public string Get() { List objListfullDetails = new List(); try { string fileName = null; bool isCreated = false; // TicketOpenModel objModel = new TicketOpenModel(); objTicketRepository = new TicketRepository(_connStr); objListfullDetails = objTicketRepository.GetAllPaymentDetailsHistory(); DataTable OpenTicketTable = objListfullDetails.ToDataTable(); Int32 OpenTicketTableColumnCount = OpenTicketTable.Columns.Count - 1; DataSet ds = new DataSet(); for (var count = OpenTicketTableColumnCount; count >= 10; count--) //modified count on 25-11-2020 //modified count from 34 to 35 on 23-12-2020 { OpenTicketTable.Columns.RemoveAt(count); } ds.Tables.Add(OpenTicketTable); ds.Tables[0].Columns[0].ColumnName = "Payment Date"; ds.Tables[0].Columns[1].ColumnName = "Time"; ds.Tables[0].Columns[2].ColumnName = "Paid By"; ds.Tables[0].Columns[3].ColumnName = "Mobile number"; ds.Tables[0].Columns[4].ColumnName = "Paid Amount"; ds.Tables[0].Columns[5].ColumnName = "Mode Of Payment"; ds.Tables[0].Columns[6].ColumnName = "Remarks"; ds.Tables[0].Columns[7].ColumnName = "Ticket Id"; ds.Tables[0].Columns[8].ColumnName = "Created by"; ds.Tables[0].Columns[9].ColumnName = "Payment updated By"; //ds.Tables[0].Columns[11].ColumnName = "Reassignment Time"; //ds.Tables[0].Columns[12].ColumnName = "Dealer Code"; //ds.Tables[0].Columns[13].ColumnName = "Dealer Name"; // ds.Tables[0].Columns.RemoveAt(7); // ds.Tables[0].Columns.RemoveAt(8); //ds.Tables[0].Columns.RemoveAt(9); // ds.Tables[0].Columns.RemoveAt(10); // ds.Tables[0].Columns.RemoveAt(11); // ds.Tables[0].Columns.RemoveAt(12); // ds.Tables[0].Columns.RemoveAt(13); // ds.Tables[0].Columns[30].ColumnName = ""; ExcelUtility objExcelUtility = new ExcelHelper.ExcelUtility(); List workbokkMapping = new List(); string _excelExportPathOnServer = ConfigurationManager.AppSettings["excelExportPathOnServer"].ToString(); fileName = "paymentReport_" + DateTime.Now.ToString("ddMMMyyyyhhmmss") + ".xlsx"; // filename = "CloseTicket_" + 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 saveAs = Server.MapPath(_excelExportPathOnServer + fileName); string SaveCsvAs = HttpContext.Current.Server.MapPath(_excelExportPathOnServer + fileName); //commented on 24-07-2020(excel download same as consolidate report) isCreated = CreateExcelFile.CreateExcelDocument(ds, SaveCsvAs); if (isCreated == true) { return _exportLocation + fileName; } else { return "error"; } } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("TicketAcceptOrDecliend_Controller", Ex.Message, path, errorlogtf); throw Ex; } // return objListfullDetails; } public List Post([FromUri] string getPaymentDetails, [FromUri] string dropdown, [FromUri] string option) { // write data log into file try { List objListfullDetails = new List(); // TicketOpenModel objModel = new TicketOpenModel(); objTicketRepository = new TicketRepository(_connStr); objListfullDetails = objTicketRepository.getPaymentDropDown(); return objListfullDetails; } catch (Exception Ex) { // write error log into file objLog.ErrorLogFile("TicketAcceptOrDecliend_Controller", Ex.Message, path, errorlogtf); throw Ex; } } #endregion } }