public IHttpActionResult GetAllGroupedSales(FilterSales filter) { string[] allowedRoles = { "RDSLS" }; string[] superRoles = { "RDSLSALL" }; bool hasSuperRight = HasRight(superRoles); bool displayPatientName = HasRight(new string[] { "VWSLSPTNT" }); if (HasRight(allowedRoles) || hasSuperRight) { var repository = new RepositorySales(); if (filter.ServiceId.HasValue) { this.ServiceId = filter.ServiceId.Value; this.IsFinanceFile = true; } if (!File.Exists(this.MapperFilePath)) { this.IsFinanceFile = false; } var response = repository.GetAllGroupedSales(filter, CurrentUser.BusinessId, CurrentUserId, hasSuperRight, CurrentUserRoles, CurrentUserDepartments, CurrentUserPrivileges, IsSalesManager || IsRep, IsSalesDirector, displayPatientName, mapperFilePath: this.MapperFilePath); return(Ok <DataResponse <EntityList <GroupedSales> > >(response)); } else { return(Ok <DataResponse>(null)); } }
// GET: Business/ReportStaticColumnConfigs public ActionResult Index() { //var reportStaticColumnConfigs = db.ReportStaticColumnConfigs.Include(r => r.LookupEnrolledService); var reportStaticColumnConfigs = new RepositorySales().GetReportStaticColumns(2); return(View(reportStaticColumnConfigs.ToList())); }
public IHttpActionResult GetReport(int id) { bool displayPatientData = HasRight(new string[] { "VWSLSPTNT" }); var repository = new RepositorySales(); var response = repository.GetReport(id, CurrentUserId, IsBuzAdmin, CurrentUserRoles, CurrentUserDepartments, CurrentUserPrivileges, IsRep || IsSalesManager, displayPatientData); return(Ok <DataResponse <EntitySales> >(response)); }
public IHttpActionResult DeleteFinance(int id) { var repository = new RepositorySales(); string[] financeDeletePrivileges = { "DLTFNANCE" }; var response = repository.DeleteFinance(id, CurrentUserId, HasRight(financeDeletePrivileges)); return(Ok <DataResponse>(response)); }
public IHttpActionResult GetFilter(int serviceId) { var objRepositorySales = new RepositorySales(); this.ServiceId = serviceId; if (File.Exists(this.MapperFilePath)) { objRepositorySales.XmlMapper = XDocument.Load(this.MapperFilePath); } bool displayPatientName = HasRight(new string[] { "VWSLSPTNT" }); return(Ok(objRepositorySales.GetDynamicFilters(CurrentBusinessId, CurrentUserId, serviceId, IsBuzAdmin, CurrentUserRoles, CurrentUserDepartments, CurrentUserPrivileges, IsSalesManager || IsRep, displayPatientName))); }
public IHttpActionResult ParseExcel(SalesEntity model) { this.ServiceId = model.ServiceId; this.IsFinanceFile = true; DataResponse response = new DataResponse(); if (!HasRight(new string[] { "SLSIMPRT" })) { return(Ok <DataResponse>(response)); } bool displayPatient = HasRight(new string[] { "VWSLSPTNT" }); if (model != null) { StringBuilder logString = new StringBuilder(); string logPath = HttpContext.Current.Server.MapPath(Path.Combine("~/Assets", CurrentBusinessId.Value.ToString(), "Sales", "Sales-Archives", "Uploads", "Logs")); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } string logFilePath = Path.Combine(logPath, string.Format("{0}.txt", DateTime.Now.ToString("MMddyyhhmmssttfff"))); if (!File.Exists(logFilePath)) { FileStream fs = File.Create(logFilePath); fs.Dispose(); } logString.AppendLine("Parsing starts @ " + DateTime.Now); logString.AppendLine("BusinessId \t:\t" + CurrentBusinessId.Value); if (model.SalesList != null && model.SalesList.Count > 0) { using (System.IO.StreamWriter logWriter = new System.IO.StreamWriter(logFilePath)) { if (!File.Exists(this.MapperFilePath)) { this.IsFinanceFile = false; } response = new RepositorySales().Insert(model.SalesList, CurrentBusinessId, CurrentUserId, model.ServiceId, this.MapperFilePath, 0, displayPatient, logWriter); } } } return(Ok <DataResponse>(response)); }
public IHttpActionResult getColumnLookups(int serviceId) { string[] allowedRoles = { "RDSLS" }; string[] superRoles = { "RDSLSALL" }; bool hasSuperRight = HasRight(superRoles); if (HasRight(allowedRoles) || hasSuperRight) { var repository = new RepositorySales(); var response = repository.GetColumnLookups(serviceId, CurrentUser.BusinessId, CurrentUserId, hasSuperRight, CurrentUserRoles, CurrentUserDepartments); return(Ok <DataResponse <EntityList <SalesColumnLookup> > >(response)); } else { return(Ok <DataResponse>(null)); } }
public IHttpActionResult GetByFilter(int reportId) { string[] allowedRoles = { "RDSLS" }; string[] superRoles = { "RDSLSALL" }; bool hasSuperRight = HasRight(superRoles); if (HasRight(allowedRoles) || hasSuperRight) { var repository = new RepositorySales(); var response = repository.GetFinanceDataList(reportId, CurrentUser.BusinessId, CurrentUserId, hasSuperRight, CurrentUserRoles, CurrentUserDepartments); return(Ok <DataResponse <EntityList <FinanceData> > >(response)); } else { return(Ok <DataResponse>(null)); } }
public IHttpActionResult GetByFilter(FilterSales filter) { string[] allowedRoles = { "RDSLS" }; string[] superRoles = { "RDSLSALL" }; bool hasSuperRight = HasSuperRight(superRoles); bool displayPatientName = HasSuperRight(new string[] { "VWSLSPTNT" }); if (HasSuperRight(allowedRoles) || hasSuperRight) { var repository = new RepositorySales(); var response = repository.GetAllList(filter, CurrentUser.BusinessId, CurrentUserId, hasSuperRight, CurrentUserRoles, CurrentUserDepartments, CurrentUserPrivileges, IsSalesManager || IsRep, IsSalesDirector, displayPatientName); return(Ok <DataResponse <EntityList <EntitySales> > >(response)); } else { return(Ok <DataResponse>(null)); } }
public void ImportSales(string basePath) { try { this.basePath = basePath; int BusinessId, ServiceId; string[] directories = Directory.GetDirectories(basePath, "*", SearchOption.TopDirectoryOnly); FileInfo fileInfo; foreach (string directory in directories) { fileInfo = new FileInfo(directory); if (int.TryParse(fileInfo.Name, out BusinessId)) { string salesPath = Path.Combine(basePath, directory, "Sales"); if (Directory.Exists(salesPath)) { string[] salesDirectories = Directory.GetDirectories(salesPath, "*", SearchOption.TopDirectoryOnly); foreach (string salesDirectory in salesDirectories) { fileInfo = new FileInfo(salesDirectory); if (fileInfo.Name != "Sales-Archives" && fileInfo.Name != "Sales-Not-Processed") { List <string> filesList = Directory.GetFiles(Path.Combine(salesPath, fileInfo.Name), "*.xls?", SearchOption.AllDirectories).ToList(); string serviceName = fileInfo.Name; ServiceId = new RepositorySales().GetServiceId(serviceName, BusinessId); if (ServiceId > 0 && filesList.Count > 0) { SaveSalesReports(filesList, BusinessId, ServiceId, serviceName, 1, directory); } } } } } } } catch (Exception ex) { ex.Log(); } }
public async void ImportFiles(string basePath) { try { // Get Box Auth Token if (!string.IsNullOrEmpty(Settings.PrivateKey)) { Settings.PrivateKey = Settings.PrivateKey.Replace("\\n", "\n"); } var boxConfig = new BoxConfig( Settings.ClientID, Settings.ClientSecret, Settings.EnterpriceId, Settings.PrivateKey, Settings.JwtPrivateKeyPassword, Settings.JwtPublicKeyId); var boxJWTAuth = new BoxJWTAuth(boxConfig); var adminToken = boxJWTAuth.AdminToken(); var client = boxJWTAuth.AdminClient(adminToken); boxManager = new BoxManager(adminToken); var enrolledServices = repositoryEnrolledService.GetServicesByImportMode(ServiceReportImportModes.BoxAPI); if (enrolledServices.Model == null || enrolledServices.Model.List.Count() == 0) { return; } foreach (var listItem in enrolledServices.Model.List) { string importPath = Path.Combine(basePath, listItem.BusinessId.ToString(), "Sales", listItem.ServiceName); BoxItem sharedItemInServiceFolder = await client.SharedItemsManager.SharedItemsAsync(listItem.BoxUrl); var sharedServiceEnties = await client.FoldersManager.GetFolderItemsAsync(sharedItemInServiceFolder.Id, 100, 0, new List <string> { BoxFolder.FieldName, BoxFolder.FieldPathCollection, BoxFolder.FieldModifiedAt, BoxFolder.FieldItemCollection } ); foreach (var sharedEntry in sharedServiceEnties.Entries) { if (sharedEntry.Type.ToLower() == "file") { bool isFileExists = new RepositorySales().IsSalesFileExists(sharedEntry.Name, listItem.BusinessId, listItem.Id) || File.Exists(Path.Combine(importPath, sharedEntry.Name)); if (isFileExists) { continue; } if (!Directory.Exists(importPath)) { Directory.CreateDirectory(importPath); } using (FileStream fileStream = new FileStream(Path.Combine(importPath, sharedEntry.Name), FileMode.CreateNew, System.IO.FileAccess.Write)) { using (Stream stream = await client.FilesManager.DownloadStreamAsync(sharedEntry.Id)) { int bytesRead; var buffer = new byte[8192]; do { bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length); await fileStream.WriteAsync(buffer, 0, bytesRead); } while (bytesRead > 0); } } // Move download file to archive folder var subfolder = new BoxApi.V2.Model.Folder(); var folderInfo = await client.FoldersManager.GetInformationAsync(sharedItemInServiceFolder.Id); if (folderInfo.ItemCollection.Entries.OfType <BoxFolder>().Count() > 0) { var foundFolder = folderInfo.ItemCollection.Entries.OfType <BoxFolder>().Any((f) => f.Name == "Archive"); // var foundFolder = entryItems.Parent.ItemCollection.Entries.OfType<BoxFolder>().First((a) => a.Name == "my subfolder"); if (foundFolder == false) { subfolder = boxManager.CreateFolder(sharedItemInServiceFolder.Id, "Archive"); boxManager.MoveFile(sharedEntry.Id, subfolder.Id); } // Move the file to the subfolder var foundFolderDetails = folderInfo.ItemCollection.Entries.OfType <BoxFolder>().First((f) => f.Name == "Archive"); boxManager.MoveFile(sharedEntry.Id, foundFolderDetails.Id); // getfolderDetails(folderItems.Id, path); } else { subfolder = boxManager.CreateFolder(sharedItemInServiceFolder.Id, "Archive"); boxManager.MoveFile(sharedEntry.Id, subfolder.Id); } } //else case entry type is 'folder' } } } catch (Exception ex) { ex.Log(); throw ex; } }
private void SaveSalesReports(List <string> filesList, int businessId, int serviceId, string serviceName, int userId = 1, string directory = "") { #region Save records to database try { DataResponse response = new DataResponse(); XmlHelper xmlHelper = new XmlHelper(); RepositorySales repositorySales = new RepositorySales(); FileInfo fileInfo; if (filesList != null && filesList.Count > 0) { foreach (var filePath in filesList) { string logPath = Path.Combine(basePath, directory, "Logs", "Sales"); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } string logFilePath = Path.Combine(logPath, string.Format("{0}.txt", DateTime.Now.ToString("MMddyyhhmmssttfff"))); if (!File.Exists(logFilePath)) { FileStream fs = File.Create(logFilePath); fs.Dispose(); } StringBuilder logString = new StringBuilder(); using (System.IO.StreamWriter logWriter = new System.IO.StreamWriter(logFilePath)) { logString.Clear(); logString.AppendLine("Parsing starts @ " + DateTime.Now); logString.AppendLine(string.Format("Total Files \t:\t{0}\t\nService Name \t:\t{1}", filesList.Count(), serviceName)); logString.AppendLine("BusinessId \t:\t" + businessId); string mapperFilePath = Path.Combine(basePath, businessId.ToString(), "Sales", serviceName, "ReportColumnMapper.xml"); if (!File.Exists(mapperFilePath)) { logString.Append(string.Format("XML mapper file is missing for the service \"{0}\"", serviceName)); continue; } xmlHelper.XmlMapper = XDocument.Load(mapperFilePath); int RecordCount; xmlHelper.xmlString = new ExcelToXml().GetXMLString(filePath, true, out RecordCount); logString.AppendLine(string.Format("File Name \t:\t{0} \t Starts @{1}", Path.GetFileName(filePath), DateTime.UtcNow)); logWriter.WriteLine(logString); logString.Clear(); int importSummeryId; response = repositorySales.Insert(xmlHelper, RecordCount, businessId, userId, serviceId, false, out importSummeryId, logWriter, incomingFileName: Path.GetFileName(filePath)); string destinationPath = Path.Combine(basePath, businessId.ToString(), "Sales", "Sales-Archives", serviceName); if (response.Status != DataResponseStatus.OK) { logString.AppendLine("ERROR occured in file"); destinationPath = Path.Combine(basePath, businessId.ToString(), "Sales", "Sales-Not-Processed", serviceName); } else { logString.AppendLine("File Successfully Processed"); } if (!Directory.Exists(destinationPath)) { Directory.CreateDirectory(destinationPath); } fileInfo = new FileInfo(filePath); string fileName = fileInfo.Name, destinationFilePath = Path.Combine(destinationPath, fileName), fileNameWithoutExt = Path.GetFileNameWithoutExtension(fileName), extension = Path.GetExtension(fileName); int count = 1; isExist: if (File.Exists(destinationFilePath)) { fileName = string.Format("{0}{1}{2}", fileNameWithoutExt, count, extension); destinationFilePath = Path.Combine(Path.GetDirectoryName(destinationFilePath), fileName); count++; goto isExist; } File.Move(filePath, destinationFilePath); logString.AppendLine("Parsing completed @ " + DateTime.Now); logString.AppendLine("File moved to :" + destinationFilePath); if (importSummeryId > 0) { repositorySales.UpdateImportSummery(importSummeryId, Path.Combine(GetRightPartOfPath(destinationFilePath, "Assets"), fileName)); } logWriter.WriteLine(logString); } new Exception(logString.ToString()).Log(logFilePath, true); } } } catch (Exception ex) { //MessageBox.Show(ex.Message); ex.Log(); } #endregion }
public IHttpActionResult ExportGroupedSalesToExcel(FilterSales filter) { var response = new DataResponse <string>(); try { #region Sales Default Export NPOI.SS.UserModel.IWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(); NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet("SalesReport"); NPOI.SS.UserModel.ICreationHelper cH = workbook.GetCreationHelper(); string[] headers = new string[] { filter.GroupBy == 1 ? "Practice Name" : filter.GroupBy == 2 ? "Rep Name" : "Sales Team", "Sales", "Last Activity On" }; var headerRow = sheet.CreateRow(0); //create header for (int i = 0; i < headers.Length; i++) { sheet.DefaultColumnWidth = 20; XSSFCellStyle style = (XSSFCellStyle)workbook.CreateCellStyle(); XSSFColor colorToFill = new XSSFColor(Color.Aqua); style.FillBackgroundColor = (short)ColorTranslator.ToWin32(Color.Aqua); headerRow.RowStyle = style; var cell = headerRow.CreateCell(i); cell.SetCellValue(headers[i]); } string[] allowedRoles = { "RDSLS" }; string[] superRoles = { "RDSLSALL" }; bool hasSuperRight = HasRight(superRoles); bool displayPatientName = HasRight(new string[] { "VWSLSPTNT" }); if (HasRight(allowedRoles) || hasSuperRight) { var repository = new RepositorySales(); var dataResponse = repository.GetAllGroupedSales(filter, CurrentUser.BusinessId, CurrentUserId, hasSuperRight, CurrentUserRoles, CurrentUserDepartments, CurrentUserPrivileges, IsRep || IsSalesManager, IsSalesDirector, displayPatientName, 10, 0, false, true, mapperFilePath: this.MapperFilePath); List <GroupedSales> salesList = dataResponse.Model.List.ToList(); int recordCount = dataResponse.Model.Pager.TotalCount; //fill content var rowIndex = 0; for (int i = 0; i < recordCount; i++) { rowIndex++; var row = sheet.CreateRow(rowIndex); var objSalesItem = salesList[i]; if (objSalesItem == null) { continue; } var font = workbook.CreateFont(); font.FontHeightInPoints = 11; font.FontName = "Calibri"; font.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold; var cell1 = row.CreateCell(0); cell1.CellStyle = workbook.CreateCellStyle(); cell1.CellStyle.SetFont(font); cell1.SetCellValue(string.IsNullOrEmpty(objSalesItem.KeyName) ? "Missing Information" : objSalesItem.KeyName); var cell2 = row.CreateCell(1); cell2.CellStyle = workbook.CreateCellStyle(); cell2.CellStyle.SetFont(font); cell2.SetCellValue(objSalesItem.Count); var cell3 = row.CreateCell(2); cell3.CellStyle = workbook.CreateCellStyle(); cell3.CellStyle.SetFont(font); cell3.SetCellValue(Convert.ToString(objSalesItem.LastActivityOn)); } string directory = Path.Combine("Assets", CurrentBusinessId.Value.ToString(), "Sales", "Sales-Archives", "Exports"); string fileUri = HttpContext.Current.Server.MapPath(Path.Combine("~/", directory)); if (!Directory.Exists(fileUri)) { Directory.CreateDirectory(fileUri); } string fileName = string.Format("{0:yyyyMMddhhmmssfff}", DateTime.Now), extension = "xlsx"; string filePath = Path.Combine(fileUri, string.Format("{0}.{1}", fileName, extension)); int count = 1; isExist: if (File.Exists(filePath)) { fileName = string.Format("{0}{1}{2}", fileName, count, extension); filePath = Path.Combine(fileUri, fileName); count++; goto isExist; } using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { workbook.Write(stream); } response.Model = Path.Combine(directory, string.Format("{0}.{1}", fileName, extension)); } return(Ok <DataResponse>(response)); #endregion } catch (Exception ex) { ex.Log(); } response.Message = "Internal Server Error"; return(Ok <DataResponse>(response)); }
public IHttpActionResult ExportAllToExcel(FilterSales filter) { var response = new DataResponse <string>(); try { if (filter.GroupBy <= 0) { #region Sales Default Export NPOI.SS.UserModel.IWorkbook workbook = new NPOI.XSSF.UserModel.XSSFWorkbook(); NPOI.SS.UserModel.ISheet sheet = workbook.CreateSheet("SalesReport"); NPOI.SS.UserModel.ICreationHelper cH = workbook.GetCreationHelper(); string[] columnname = filter.DynamicFilters.Where(a => a.IsVisible == true).Select(a => a.ColumnName).ToArray(); string[] headers, columns = null; headers = columns = columnname; columns = columns.Select(x => x.Replace("SalesTeam", "RepGroup")).ToArray(); columns = columns.Select(x => x.Replace("CollectedDate", "CollectionDate")).ToArray(); //byte[] rgb = new byte[3] { 22, 183, 223 }; //XSSFCellStyle HeaderCellStyle = (XSSFCellStyle)workbook.CreateCellStyle(); //HeaderCellStyle.SetFillBackgroundColor(new XSSFColor(rgb)); var headerRow = sheet.CreateRow(0); //headerRow.RowStyle.FillBackgroundColor= (short)ColorTranslator.ToWin32(Color.Aqua); //create header for (int i = 0; i < headers.Length; i++) { sheet.DefaultColumnWidth = 20; XSSFCellStyle style = (XSSFCellStyle)workbook.CreateCellStyle(); XSSFColor colorToFill = new XSSFColor(Color.Aqua); style.FillBackgroundColor = (short)ColorTranslator.ToWin32(Color.Aqua); headerRow.RowStyle = style; var cell = headerRow.CreateCell(i); cell.SetCellValue(headers[i]); } string[] allowedRoles = { "RDSLS" }; string[] superRoles = { "RDSLSALL" }; bool hasSuperRight = HasRight(superRoles); bool displayPatientName = HasRight(new string[] { "VWSLSPTNT" }); if (HasRight(allowedRoles) || hasSuperRight) { var repository = new RepositorySales(); var dataResponse = repository.GetAllList(filter, CurrentUser.BusinessId, CurrentUserId, hasSuperRight, CurrentUserRoles, CurrentUserDepartments, CurrentUserPrivileges, IsRep || IsSalesManager, IsSalesDirector, displayPatientName, 10, 0, false, true, mapperFilePath: this.MapperFilePath); List <EntitySales> salesList = dataResponse.Model.List.ToList(); int recordCount = dataResponse.Model.Pager.TotalCount; //fill content var rowIndex = 0; for (int i = 0; i < recordCount; i++) { rowIndex++; var row = sheet.CreateRow(rowIndex); for (int j = 0; j < columns.Length; j++) { var font = workbook.CreateFont(); font.FontHeightInPoints = 11; font.FontName = "Calibri"; font.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold; var cell = row.CreateCell(j); cell.CellStyle = workbook.CreateCellStyle(); cell.CellStyle.SetFont(font); string value = null; var objSalesItem = salesList[i]; var objStaticItem = objSalesItem.GetType().GetTypeInfo().GetProperty(columns[j]); if (objStaticItem != null) { var property = salesList[i].GetType().GetRuntimeProperties().FirstOrDefault(p => string.Equals(p.Name, objStaticItem.Name, StringComparison.OrdinalIgnoreCase)); if (property != null) { value = Convert.ToString(property.GetValue(salesList[i], null)); } } else { var objDynamicItem = objSalesItem.ReportColumnValues.FirstOrDefault(a => a.ColumnName == columns[j]); if (objDynamicItem != null) { value = objDynamicItem.Value; } } cell.SetCellValue(value); } bool isFinanceDataCount = salesList[i].FinanceDataRecordCount > 1; if (isFinanceDataCount) { for (int k = 0; k < salesList[i].FinanceDataRecordCount; k++) { rowIndex++; var financeRow = sheet.CreateRow(rowIndex); for (int j = 0; j < columns.Length; j++) { var cell = financeRow.CreateCell(j); string value = null; var objSalesItem = salesList[i].FinanceDataList.ToList()[k]; var objStaticItem = objSalesItem.GetType().GetProperty(columns[j]); if (objStaticItem != null) { value = Convert.ToString(objStaticItem.GetValue(objSalesItem, null)); } else { var objDynamicItem = objSalesItem.FinanceColumnValues.FirstOrDefault(a => a.ColumnName == columns[j]); if (objDynamicItem != null) { value = objDynamicItem.Value; } } cell.SetCellValue(value); } } } } string directory = Path.Combine("Assets", CurrentBusinessId.Value.ToString(), "Sales", "Sales-Archives", "Exports"); string fileUri = HttpContext.Current.Server.MapPath(Path.Combine("~/", directory)); if (!Directory.Exists(fileUri)) { Directory.CreateDirectory(fileUri); } string fileName = string.Format("{0:yyyyMMddhhmmssfff}", DateTime.Now), extension = "xlsx"; string filePath = Path.Combine(fileUri, string.Format("{0}.{1}", fileName, extension)); int count = 1; isExist: if (File.Exists(filePath)) { fileName = string.Format("{0}{1}{2}", fileName, count, extension); filePath = Path.Combine(fileUri, fileName); count++; goto isExist; } using (FileStream stream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { workbook.Write(stream); } response.Model = Path.Combine(directory, string.Format("{0}.{1}", fileName, extension)); } return(Ok <DataResponse>(response)); #endregion } #region Sales Grouped Report return(ExportGroupedSalesToExcel(filter)); #endregion } catch (Exception ex) { ex.Log(); } response.Message = "Internal Server Error"; return(Ok <DataResponse>(response)); }
public IHttpActionResult ParseExcel(EntitySales model) { try { #region Upload file, Save records to database this.IsFinanceFile = model.IsFinanceFile; if (!HasRight(new string[] { "SLSIMPRT" })) { return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = new { Message = "Unauthorized Operation" } })); } DataResponse response = new DataResponse(); if (model.Files != null && model.Files.Count > 0) { StringBuilder logString = new StringBuilder(); string logPath = HttpContext.Current.Server.MapPath(Path.Combine("~/Assets", CurrentBusinessId.Value.ToString(), "Sales", "Sales-Archives", "Uploads", "Logs")); if (!Directory.Exists(logPath)) { Directory.CreateDirectory(logPath); } string logFilePath = Path.Combine(logPath, string.Format("{0}.txt", DateTime.Now.ToString("MMddyyhhmmssttfff"))); if (!File.Exists(logFilePath)) { FileStream fs = File.Create(logFilePath); fs.Dispose(); } logString.AppendLine("Parsing starts @ " + DateTime.Now); logString.AppendLine("BusinessId \t:\t" + CurrentBusinessId.Value); List <FileInfo> FilesList = new List <FileInfo>(); string serviceName = new RepositoryLookups().GetServiceNameById(model.ServiceId); foreach (var file in model.Files) { string FileName = SaveFile(file.Base64, file.FileName, serviceName); FilesList.Add(new FileInfo { SavedFileName = FileName, IncomingFileName = file.FileName }); } logString.AppendLine(string.Format("Total Files \t:\t{0}\t\nService Id \t:\t{1}", FilesList.Count(), model.ServiceId)); foreach (var fileInfo in FilesList) { XmlHelper xmlHelper = new XmlHelper(); string uploadPath = Path.Combine(CurrentBusinessId.Value.ToString(), "Sales", "Sales-Archives", "Uploads", serviceName, fileInfo.SavedFileName); string excelFile = HttpContext.Current.Server.MapPath(Path.Combine("~/Assets", uploadPath)); string importedPath = Path.Combine("Assets", uploadPath); this.ServiceId = model.ServiceId; if (this.MapperFilePath == null) { logString.Append(string.Format("XML mapper file is missing for the service \"{0}\"", serviceName)); continue; } xmlHelper.XmlMapper = XDocument.Load(this.MapperFilePath); int RecordCount; xmlHelper.xmlString = new ExcelToXml().GetXMLString(excelFile, true, out RecordCount); logString.AppendLine(string.Format("File Name \t:\t{0} \t Starts @{1}", fileInfo.SavedFileName, DateTime.UtcNow)); using (System.IO.StreamWriter logWriter = new System.IO.StreamWriter(logFilePath)) { logWriter.WriteLine(logString); logString.Clear(); int importSummeryId; response = new RepositorySales().Insert(xmlHelper, RecordCount, CurrentBusinessId, CurrentUserId, model.ServiceId, IsFinanceFile, out importSummeryId, logWriter, "Web Upload", importedPath, fileInfo.IncomingFileName); logString.AppendLine("File Successfully Processed"); logString.AppendLine("File moved to :" + excelFile); logWriter.WriteLine(logString); } } new Exception(logString.ToString()).Log(logFilePath, true); } HttpRuntime.Cache[CurrentUserId.ToString()] = true; return(Ok <DataResponse>(response)); #endregion } catch (Exception ex) { ex.Log(); return(Ok <dynamic>(new { Status = HttpStatusCode.BadRequest, Model = new { Message = string.Format("{0}|{1}", ex.Message, ex.InnerException != null ? ex.InnerException.Message : "") } })); } }