Exemple #1
0
        public ActionResult OnEdit(ProductImageModels productImage)
        {
            var productImageUpdate = ProductImageService.Find(productImage.Id);

            if (productImageUpdate == null)
            {
                return(RedirectToAction("Edit", "Product", new
                {
                    id = productImage.ProductId
                }));
            }
            productImageUpdate.Name = productImage.Image != null?
                                      productImage.Image.Upload() :
                                          productImage.ImageUrl.ToImageOriginalPath();

            productImageUpdate.ProductID = productImage.ProductId;
            productImageUpdate.Title     = productImage.Title;
            productImageUpdate.Number    = Convert.ToInt32(productImage.Number);
            var result = ProductImageService.Update(productImageUpdate);

            if (result == Result.NotExists)
            {
                ModelState.AddModelError("", "Id không tồn tại trên hệ thống.");
                return(View("Edit", productImage));
            }
            SetFlashMessage($"Cập nhật ảnh '{productImageUpdate.Title}' thành công.");
            if (productImage.SaveList)
            {
                return(RedirectToAction("Edit", "Product", new
                {
                    id = productImage.ProductId
                }));
            }
            return(View("Edit", productImage));
        }
Exemple #2
0
        public ActionResult Edit(int id, int productId)
        {
            var productImage = ProductImageService.Find(id);

            if (productImage == null)
            {
                return(RedirectToAction("Edit", "Product", new
                {
                    id = productId
                }));
            }
            return(View("Edit", productImage.CloneTo <ProductImageModels>()));
        }