public ActionResult SelectCompany(int id) { int errorCode = 0; MembershipManagementService.SaveProperty(MMSProperty.CurrentCompany, id); return(Json(errorCode, JsonRequestBehavior.AllowGet)); }
public ActionResult Import(EditDataMappingViewModel model, string command) { if (command.ToLower() == "import") { var error = ProductService.ValidateProducts(CurrentCompany, CurrentUser, model.Data.Headings); if (error.IsError) { prepareViewModel(model); model.Data = FileImportService.GetData(CurrentCompany, CurrentUser); model.SetError(ErrorIcon.Error, error.Message); return(View("ImportMappings", model)); } else { error = ProductService.ImportProducts(CurrentCompany, CurrentUser, model.Data.Headings, MembershipManagementService.GetProperty("ProdImportZip", "")); 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 MembershipManagementService.SaveProperty("ProdImportZip", ""); return(RedirectToAction("Products", "Products", new { Area = "Products" })); } } } else { return(RedirectToAction("Index")); } }
public void SavePropertyTest() { var user = GetTestUser(); MembershipManagementService.User = user; // So we save properties against this user for (int i = 1; i < 50; i++) { string propName = "Prop" + i.ToString(); // Set a string value string propValue1 = RandomString(); MembershipManagementService.SaveProperty(propName, propValue1); string stringValue = MembershipManagementService.GetProperty(propName, ""); Assert.IsTrue(propValue1 == stringValue, $"Error: Property {propName} returned {stringValue} when {propValue1} was expected"); // Set an int value int propValue2 = RandomInt(); MembershipManagementService.SaveProperty(propName, propValue2); int intValue = MembershipManagementService.GetProperty(propName, 0); Assert.IsTrue(propValue2 == intValue, $"Error: Property {propName} returned {intValue} when {propValue2} was expected"); // set a date-time value DateTime propValue3 = RandomDateTime(); MembershipManagementService.SaveProperty(propName, propValue3); DateTime dateTimeValue = MembershipManagementService.GetProperty(propName, new DateTime(1900, 1, 1, 0, 0, 0)); // We compare the strings because the date values are sub-millisecond different Assert.IsTrue(propValue3.ToString() == dateTimeValue.ToString(), $"Error: Property {propName} returned {dateTimeValue} when {propValue3} was expected"); } }
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() == 1 && model.Images != null || model.Images.Count() == 1) { var targetFolder = Path.GetTempPath(); string prodFile = "", zipFile = ""; try { var attachment = model.Files.FirstOrDefault(); if (attachment != null) { string fileName = attachment.FileName; if (!MediaServices.IsValidOrderImportType(fileName)) { model.SetError(ErrorIcon.Error, EvolutionResources.errInvalidImportFile.Replace("%1", MediaServices.GetValidOrderImportTypes())); } else if (attachment.ContentLength > 0) { prodFile = targetFolder + fileName.FileName(); attachment.SaveAs(prodFile); } if (!model.Error.IsError) { attachment = model.Images.FirstOrDefault(); if (attachment != null) { fileName = attachment.FileName; if (fileName.FileExtension().ToLower() != "zip") { model.SetError(ErrorIcon.Error, EvolutionResources.errInvalidImportFile.Replace("%1", "zip")); } else if (attachment.ContentLength > 0) { zipFile = targetFolder + fileName.FileName(); attachment.SaveAs(zipFile); MembershipManagementService.SaveProperty("ProdImportZip", zipFile); } } } } } catch (Exception e1) { model.Error.SetError(e1); } if (!model.Error.IsError) { try { model.Error = FileImportService.UploadFile(CurrentCompany, CurrentUser, prodFile, model.FirstLineContainsHeader); if (!model.Error.IsError) { // Display the table var mappingsModel = new EditDataMappingViewModel(); prepareViewModel(mappingsModel); mappingsModel.Data = FileImportService.GetData(CurrentCompany, CurrentUser); ProductService.ValidateProducts(CurrentCompany, CurrentUser, mappingsModel.Data.Headings); mappingsModel.Data = FileImportService.GetData(CurrentCompany, CurrentUser); return(View("ImportMappings", mappingsModel)); } } catch (Exception e1) { model.SetError(ErrorIcon.Error, EvolutionResources.errFailedToUploadFile.Replace("%1", prodFile).Replace("%2", e1.Message)); LogService.WriteLog(e1, Request.RawUrl); } } MediaService.MediaService.DeleteFile(prodFile); MediaService.MediaService.DeleteFile(zipFile); PrepareViewModel(model, EvolutionResources.bnrProductImport, 0, 0); return(View("ProductImport", model)); } } return(RedirectToAction("Index")); }