public ActionResult Create(Category category) { if (ModelState.IsValid) { db.Categorys.Add(category); db.SaveChanges(); return RedirectToAction("Index"); } return View(category); }
public int Create(string name) { var newCategory = new Category { Name = name }; this.categories.Add(newCategory); this.categories.SaveChanges(); return newCategory.Id; }
public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category) { if (category != null && ModelState.IsValid) { var newCategory = new Category { Name=category.Name }; this.db.Categories.Add(newCategory); this.db.SaveChanges(); category.Id = newCategory.Id; } return Json(new[] { category }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet); }
public ActionResult Edit(Category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(category); }