public ActionResult Edit(CategoryViewModel model) { if (ModelState.IsValid) { Category category = new Category { Name = model.Name, CategoryId = model.Id }; db.AddCategory(category); return RedirectToAction("Index", "Home"); } return View(model); }
void IPortfolioDataSource.AddCategory(Category category) { if (category.CategoryId != 0) { var entry = Categories.Find(category.CategoryId); Entry<Category>(entry).CurrentValues.SetValues(category); SaveChanges(); return; } Categories.Add(category); SaveChanges(); }