Пример #1
0
        public async Task <int> Edit(ProductUpdateDeleteViewModel model)
        {
            var product = this.context.Products.FirstOrDefault(p => p.Id == model.Id);

            if (product == null)
            {
                return(0);
            }

            product.Name        = model.Name;
            product.Description = model.Description;
            product.Type        = (ProductType)Enum.Parse(typeof(ProductType), model.Type);
            product.Price       = decimal.Parse(model.Price);

            try
            {
                int result = await this.context.SaveChangesAsync();

                return(result);
            }
            catch (Exception)
            {
                throw new InvalidOperationException();
            }
        }
Пример #2
0
        public async Task <IActionResult> Edit(ProductUpdateDeleteViewModel model)
        {
            int result = await this.productService.Edit(model);

            if (result == 1)
            {
                return(RedirectToAction("Details", "Products", new { id = model.Id }));
            }
            else
            {
                return(BadRequest());
            }
        }
Пример #3
0
        public IActionResult Edit(string productId)
        {
            var product = this.productService.GetProductById(productId);

            if (product == null)
            {
                return(RedirectToAction("Index", "Home"));
            }

            var model = new ProductUpdateDeleteViewModel
            {
                Id          = productId,
                Name        = product.Name,
                Price       = product.Price.ToString(),
                Description = product.Description,
                Type        = product.Type.ToString()
            };

            return(this.View(model));
        }