public ActionResult Destroy([DataSourceRequest] DataSourceRequest request, ViewModel model)
        {
            if (model != null) // && ModelState.IsValid
            {
                var category = this.data.Categories.Find(model.Id.Value);

                foreach (var pageId in category.Pages.Select(t => t.Id).ToList())
                {
                    var comments = this.data
                                   .Comments
                                   .All()
                                   .Where(c => c.PageId == pageId)
                                   .Select(c => c.Id)
                                   .ToList();

                    foreach (var commentId in comments)
                    {
                        this.data.Comments.Delete(commentId);
                    }

                    this.data.SaveChanges();

                    this.data.Pages.Delete(pageId);
                }

                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));
 }