示例#1
0
        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"));
        }