private void prepareViewModel(EditSaleImportDataMappingsViewModel model) { PrepareViewModel(model, EvolutionResources.bnrSaleImport, 0, 0); model.HeadingList = FileImportService.GetHeadingList("Sale.dat"); model.SOStatusList = LookupService.FindSalesOrderHeaderStatusListItemModel(); model.SourceList = LookupService.FindLOVItemsListItemModel(CurrentCompany, LOVName.OrderSource); }
public ActionResult Upload(FileUploadViewModel model, string command) { Server.ScriptTimeout = 600; // Allow 10 minutes for an upload/import if (command.ToLower() == "upload") { if (model.Files != null && model.Files.Count() > 0) { var targetFile = Path.GetTempPath(); var attachment = model.Files.FirstOrDefault(); string fileName = attachment.FileName; if (!MediaServices.IsValidOrderImportType(fileName)) { model.SetError(ErrorIcon.Error, EvolutionResources.errInvalidImportFile.Replace("%1", MediaServices.GetValidOrderImportTypes())); } else if (attachment != null && attachment.ContentLength > 0) { try { targetFile += fileName.FileName(); attachment.SaveAs(targetFile); var error = FileImportService.UploadFile(CurrentCompany, CurrentUser, targetFile, model.FirstLineContainsHeader); if (error.IsError) { model.SetError(ErrorIcon.Error, error.Message); } else { // Display the table var mappingsModel = new EditSaleImportDataMappingsViewModel(); prepareViewModel(mappingsModel); mappingsModel.Data = FileImportService.GetData(CurrentCompany, CurrentUser); SalesService.ValidateOrders(CurrentCompany, CurrentUser, mappingsModel.Data.Headings, mappingsModel.DisplayDateFormat); mappingsModel.Data = FileImportService.GetData(CurrentCompany, CurrentUser); return(View("ImportMappings", mappingsModel)); } } catch (Exception e1) { model.SetError(ErrorIcon.Error, EvolutionResources.errFailedToUploadFile.Replace("%1", fileName).Replace("%2", e1.Message)); LogService.WriteLog(e1, Request.RawUrl); } } prepareViewModel(model); return(View("SaleImport", model)); } } return(RedirectToAction("Index")); }
public ActionResult Import(EditSaleImportDataMappingsViewModel model, string command) { if (command.ToLower() == "import") { var error = SalesService.ValidateOrders(CurrentCompany, CurrentUser, model.Data.Headings, CurrentUser.DateFormat); if (error.IsError) { prepareViewModel(model); model.Data = FileImportService.GetData(CurrentCompany, CurrentUser); model.SetError(ErrorIcon.Error, error.Message); return(View("ImportMappings", model)); } else { error = SalesService.ImportSales(CurrentCompany, CurrentUser, model.SOStatus, model.SourceId, model.Data.Headings, CurrentUser.DateFormat, model.TZ.ParseInt()); if (error.IsError) { prepareViewModel(model); model.Data = FileImportService.GetData(CurrentCompany, CurrentUser); model.SetError(ErrorIcon.Error, error.Message); return(View("ImportMappings", model)); } else { // Successfully imported, so redirect to purchase orders screen return(RedirectToAction("Sales", "Sales", new { Area = "Sales" })); } } } else { return(RedirectToAction("Index")); } }