public ActionResult Update(ManufacturerViewModel model) { if (ModelState.IsValid) { bool isNotExist = _manufacturersRepository.FindDuplicateByNameAndId(model.Name, model.Id); if (isNotExist) { var manufacturer = _manufacturersRepository.Get(model.Id); manufacturer.Update(model.Name); try { _manufacturersRepository.Update(manufacturer); TempData["success"] = String.Format("Edycja producenta {0} wykonana pomyślnie", manufacturer.Name); return RedirectToAction("List"); } catch (Exception) { TempData["error"] = "Wystąpił problem z połączeniem do bazy danych."; return RedirectToAction("Update", new {@id = model.Id}); } } TempData["error"] = String.Format("Producent o nazwie {0} już istnieje", model.Name); } else { TempData["error"] = "Nazwa producenta jest wymagana"; } return RedirectToAction("Update", new {@id = @model.Id}); }
public ActionResult Update(int id) { var manufacturer = _manufacturersRepository.Get(id); if (manufacturer == null) return RedirectToAction("List", "ManageManufacturers"); var categoryModel = new ManufacturerViewModel { Name = manufacturer.Name, Id = manufacturer.ID }; return View(categoryModel); }