public ActionResult Images(int id) { var model = new ProductImageUploadViewModel(); model.Product = ProductService.FindProductModel(id, 0, CurrentCompany); model.MaxUploadFileSize = GetMaxFileUploadSize(); model.ValidFileTypes = MediaServices.GetValidImageTypes(); PrepareViewModel(model, EvolutionResources.bnrImages + (id == 0 ? "" : " - " + model.Product.ItemName), id, MakeMenuOptionFlags(0, 0, 0, 0, id)); return(View("Images", model)); }
public ActionResult DoUpload(ProductImageUploadViewModel model) { var error = new Error(); var product = ProductService.FindProductModel(model.Product.Id, null, null, false); if (product == null) { error.SetRecordError("Product", model.Product.Id); } else { if (model.Images != null || model.Images.Count() > 0) { var fileList = new List <string>(); var targetFolder = MediaServices.GetMediaFolder(CurrentCompany.Id) + "\\Temp\\"; foreach (var file in model.Images) { string targetFile = targetFolder + file.FileName; try { db.AddFileToLog(targetFile, 2); file.SaveAs(targetFile); var prodMedia = new ProductMediaModel(); error = ProductService.AddMediaToProduct(product, CurrentCompany, CurrentUser, targetFile, prodMedia, FileCopyType.Move); } catch (Exception ex) { model.SetError(ex, "", true); break; } } if (!error.IsError) { model.SetErrorOnField(ErrorIcon.Information, EvolutionResources.infImagesSuccessfullyUploaded, "", null, null, null, null, true); } } } return(RedirectToAction("Images", "Images", new { Id = model.Product.Id })); }