コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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));
        }