コード例 #1
0
        public ActionResult Edit(int id, ProductsCreateAndEdit products)
        {
            var productEiditView = new ProductEiditViewModel();

            if (id != products.IdProducts)
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                try
                {
                    var productsEdit = productsContext.FindId(id);
                    productsEdit.category          = products.Category;
                    productsEdit.title             = products.Title;
                    productsEdit.cost              = products.Cost;
                    productsEdit.described         = products.Described;
                    productsEdit.dateOfManufacture = products.DateOfManufacture;
                    productsContext.Update(productsEdit);
                    Program.logger.Debug("Успешно изменён продукт с индентификатором: " + productsEdit.idProducts);

                    Program.logger.Debug("Успешно сохранён");
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    Program.logger.Error(ex.Message);
                    return(NotFound());
                }
                return(Ok("Ok"));
            }
            try
            {
                productEiditView.products       = products;
                productEiditView.categoriesList = new SelectList(categoriesContext.GetAll(), "idCategory", "title", productEiditView.products.Category);
            }
            catch (Exception ex)
            {
                Program.logger.Error(ex.Message);
            }
            return(PartialView(productEiditView));
        }
コード例 #2
0
        public ActionResult Edit(int id)
        {
            var productEiditView = new ProductEiditViewModel();

            if (id == null)
            {
                return(NotFound());
            }
            Program.stopwatch.Start();
            var items = productsContext.FindId(id);

            Program.stopwatch.Stop();
            Program.logger.Debug("Успешно получен продукт с индентификатором: " + items.idProducts + $"Затраченное время: {Program.stopwatch.Elapsed}");
            productEiditView.products = new ProductsCreateAndEdit()
            {
                IdProducts        = items.idProducts,
                Category          = items.category,
                Title             = items.title,
                Cost              = items.cost,
                Described         = items.described,
                DateOfManufacture = items.dateOfManufacture
            };
            if (productEiditView.products == null)
            {
                return(NotFound());
            }
            try
            {
                productEiditView.categoriesList = new SelectList(categoriesContext.GetAll(), "idCategory", "title", productEiditView.products.Category);
            }
            catch (Exception ex)
            {
                Program.logger.Error(ex.Message);
            }
            return(PartialView(productEiditView));
        }