public void Edit(CategoryToEditViewModel categoryToEdit) { Category category = _dbContext.Categories.FirstOrDefault(c => c.CategoryId == categoryToEdit.CategoryId); category.Name = categoryToEdit.Name; _dbContext.Entry(category).State = EntityState.Modified; _dbContext.SaveChanges(); }
public ActionResult Edit([Bind(Include = "CategoryId,Name")] CategoryToEditViewModel category) { if (ModelState.IsValid) { _categoryService.Edit(category); return(RedirectToAction("Index")); } return(View(category)); }
// GET: Categories/Edit/5 public ActionResult Edit(Guid?categoryId) { if (categoryId == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Category category = _categoryService.GetCategoryById(categoryId); if (category == null) { return(HttpNotFound()); } CategoryToEditViewModel categoryToEdit = new CategoryToEditViewModel() { CategoryId = category.CategoryId, Name = category.Name }; return(View(categoryToEdit)); }