public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ViewModel model) { if (model != null && ModelState.IsValid) { var category = this.Data.Categories.GetById(model.Id.Value); foreach (var ticketId in category.Tickets.Select(t => t.Id).ToList()) { var comments = this.Data .Comments .All() .Where(c => c.TicketId == ticketId) .Select(c => c.Id) .ToList(); foreach (var commentId in comments) { this.Data.Comments.Delete(commentId); } this.Data.SaveChanges(); this.Data.Tickets.Delete(ticketId); } this.Data.SaveChanges(); this.Data.Categories.Delete(category); this.Data.SaveChanges(); } this.ClearCategoryCache(); return(this.GridOperation(model, request)); }
public ActionResult Create([DataSourceRequest] DataSourceRequest request, ViewModel model) { var dbModel = base.Create <Model>(model); if (dbModel != null) { model.Id = dbModel.Id; } this.ClearCategoryCache(); return(this.GridOperation(model, request)); }
public ActionResult Update([DataSourceRequest] DataSourceRequest request, ViewModel model) { base.Update <Model, ViewModel>(model, model.Id); this.ClearCategoryCache(); return(this.GridOperation(model, request)); }