Esempio n. 1
0
        public async Task EditAsync(ProductListingServiceModel product)
        {
            var productForEdit = this.db.Products.Where(a => a.Id == product.Id).FirstOrDefault();

            productForEdit.Title   = product.Title;
            productForEdit.Content = product.Content;

            if (!string.IsNullOrEmpty(product.ImageName))
            {
                productForEdit.ImageName = product.ImageName;
            }

            this.db.Products.Update(productForEdit);

            await this.db.SaveChangesAsync();
        }
Esempio n. 2
0
        public async Task <IActionResult> Edit(ProductListingServiceModel product, IFormFile Image)
        {
            if (!ModelState.IsValid)
            {
                return(View(product));
            }

            product.Content = this.html.Sanitize(product.Content);

            if (Image != null)
            {
                product.ImageName = await SaveImage(Image);
            }


            await this.productService.EditAsync(product);

            TempData[WebConstants.TempDataSuccessMessageKey] = ($"Product {product.Title} successfuly updated.");
            return(RedirectToAction(nameof(ProductController.Index), new { page = 1 }));
        }