public ActionResult Edit(int id, [Bind("CategoryId,Name")] Category category) { if (id != category.CategoryId) { return(NotFound()); } if (ModelState.IsValid) { try { _categoriesRepository.EditCategory(category); } catch (DbUpdateConcurrencyException) { if (!_categoriesRepository.CategoryExists(category.CategoryId)) { return(NotFound()); } else { throw; } } ViewBag.SelectedNav = "Dashboard"; return(RedirectToAction(nameof(Index))); } ViewBag.SelectedNav = "Dashboard"; return(View(category)); }
public Category EditCategory(Category categoryData) { var tag = _repo.GetCatActionById(categoryData.Id);//TODO find cataction by its categoryId if (tag != null) { throw new Exception("cannot edit Category"); } var category = _repo.GetCategoryById(categoryData.Id); category.Name = categoryData.Name; bool success = _repo.EditCategory(category); if (!success) { throw new Exception("Could not edit review"); } return(category); }