public async Task <ActionResult> Edit(ProductsCreateEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         using (var context = new ApplicationDbContext())
         {
             IUnitOfWork unitOfWork = new UnitOfWork(context);
             Product     product    = unitOfWork.Products.FirstOrDefault(x => x.Id == model.Id);
             if (product == null)
             {
                 return(NotFound());
             }
             product.Name = model.Name;
             product.Cost = model.Cost;
             try
             {
                 await unitOfWork.SaveAsync();
             }
             catch (Exception e)
             {
                 Log.Error($"ProductsContainer.Edit: Ошибка при попытке сохранения продукта: {DateTime.Now}" +
                           $"{Environment.NewLine}{e}{Environment.NewLine}");
                 throw new Exception($"Ошибка при попытке сохранения продукта: {e}");
             }
         }
     }
     return(View("Index"));
 }
        public ActionResult Edit(int id)
        {
            Product product;
            ProductsCreateEditViewModel model = new ProductsCreateEditViewModel();

            using (var context = new ApplicationDbContext())
            {
                IUnitOfWork unitOfWork = new UnitOfWork(context);
                product = unitOfWork.Products.FirstOrDefault(x => x.Id == id);
            }
            if (product == null)
            {
                return(NotFound());
            }
            model.Id   = id;
            model.Name = product.Name;
            model.Cost = product.Cost;

            return(View(model));
        }