public ActionResult Update([DataSourceRequest] DataSourceRequest request, CategoryViewModel model) { if (model != null && ModelState.IsValid) { var category = this.Db.Categories.GetById(model.Id); category.Name = model.Name; this.Db.SaveChanges(); } return Json(new[] { model }.ToDataSourceResult(request, ModelState)); }
public ActionResult Create([DataSourceRequest] DataSourceRequest request, CategoryViewModel category) { if (category != null && ModelState.IsValid) { this.Db.Categories.Add(new Category() { Name = category.Name }); this.Db.SaveChanges(); } return Json(new[] {category}.ToDataSourceResult(request, ModelState)); }
public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, CategoryViewModel category) { if (category != null) { var dbCategory = this.Db.Categories.GetById(category.Id); var tickets = dbCategory.Tickets.ToList(); foreach (var ticket in tickets) { this.Db.Tickets.Delete(ticket); } this.Db.Categories.Delete(dbCategory); this.Db.SaveChanges(); } return Json(new[] { category }.ToDataSourceResult(request, ModelState)); }