public IActionResult Modify(ModifyProductCustomViewModel form) { var modifProduct = new Product(); if (form.newImages.Count != 0) { foreach (var image in _repo.GetImages(form.ProductId)) { System.IO.File.Delete($"C:/Users/Mr/RiderProjects/E_Commerce/E_Commerce/wwwroot/images/{image.Path}"); } var up = new FilesUploading(_environment, "images"); up.StageRange(form.newImages); up.Save(); modifProduct.Images = up.GetFilesObjects <Image>(); _repo.DeleteAllImages(form.ProductId); } var oldQuantity = _repo.Get(form.ProductId).Quantity; modifProduct.CategoryId = form.CategoryId; modifProduct.Name = form.Name; modifProduct.Id = form.ProductId; modifProduct.Price = form.Price; modifProduct.Quantity = oldQuantity; _repo.Update(modifProduct); return(RedirectToAction("Add")); }
public IActionResult Create(ProductForm form) { var up = new FilesUploading(_environment, "images"); up.StageRange(form.Images); up.Save(); _repo.Insert(new Product { CategoryId = form.CategoryId, Images = up.GetFilesObjects <Image>(), Name = form.Name, Price = form.Price, Quantity = form.Quantity }); return(RedirectToAction("Add")); }