public ActionResult Delete([DataSourceRequest] DataSourceRequest request,
            CategoryShortViewModel categoryModel)
        {
            if (categoryModel != null)
            {
                var category = this.Data.Categories.GetById(categoryModel.Id);

                using (var tran = new TransactionScope())
                {
                    // the cascade delete will take care of the category tickets but
                    // we have to delete all the related comments manually
                    var commentsToDeleteIds = this.Data.Comments.All().Include("Ticket").
                        Include("Ticket.Category").
                        Where(c => c.Ticket.CategoryId == category.Id).Select(c => c.Id).ToList();

                    foreach (var comment in commentsToDeleteIds)
                    {
                        this.Data.Comments.Delete(comment);
                    }

                    this.Data.SaveChanges();

                    this.Data.Categories.Delete(category);
                    this.Data.SaveChanges();

                    tran.Complete();
                }
            }

            return Json(new[] { categoryModel }.ToDataSourceResult(request, ModelState));
        }
        public ActionResult Edit([DataSourceRequest] DataSourceRequest request,
            CategoryShortViewModel categoryModel)
        {
            if (categoryModel != null && ModelState.IsValid)
            {
                var category = this.Data.Categories.All().Where(c => c.Id == categoryModel.Id).FirstOrDefault();

                if (category != null)
                {
                    category.Title = categoryModel.Title;
                    this.Data.SaveChanges();
                }
            }

            return Json(new[] { categoryModel }.
                ToDataSourceResult(request, ModelState));
        }
        public ActionResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryShortViewModel categoryModel)
        {
            if (categoryModel != null && ModelState.IsValid)
            {
                Category category = new Category
                {
                    Title = categoryModel.Title
                };

                this.Data.Categories.Add(category);
                this.Data.SaveChanges();
            }

            return Json(new[] { categoryModel }.ToDataSourceResult(request, ModelState));
        }