public JsonResult DestroyCategories([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            var cat = this.Data.Categories.GetById(category.Id);

            var tickets = cat.Tickets.ToList();
            foreach (var ticket in tickets)
            {
                ticket.Author = null;

                var comments = ticket.Comments.ToList();
                foreach (var comment in comments)
                {
                    this.Data.Commetns.Delete(comment);

                }

                this.Data.Tickets.Delete(ticket);
            }



            this.Data.Categories.Delete(cat);

            this.Data.SaveChanges();

            return Json(new[] { category }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        public JsonResult UpdateCommand([DataSourceRequest] DataSourceRequest request, CategoryViewModel model)
        {
            var entity = this.Data.Categories.GetById(model.Id);

            entity.Name = model.Name;
            this.Data.SaveChanges();

            return Json(new[] { model }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        public JsonResult UpdateCategories([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            var categoryDb = this.Data.Categories.GetById(category.Id);

            categoryDb.Name = category.Name;
            this.Data.SaveChanges();

            return Json(new[] { category }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        public JsonResult DestroyCommand([DataSourceRequest] DataSourceRequest request, CategoryViewModel model)
        {
            var tickets = Data.Tickets.All().Where(x => x.CategoryId == model.Id).ToList();
            foreach (var ticket in tickets)
            {
                Data.Tickets.Delete(ticket);
            }
            this.Data.Categories.Delete(model.Id);
            this.Data.SaveChanges();

            return Json(new[] { model }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 5
0
        public ActionResult Delete([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            if (ModelState.IsValid)
            {
                // Delete is cascading!!!
                var categoryForDelete = this.Data.Categories.GetById(category.Id);
                this.Data.Categories.Delete(categoryForDelete);
                this.Data.SaveChanges();
            }

            return Json(new[] { category }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 6
0
        public JsonResult UpdateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            var existingCategory = this.Data.Categories.All().FirstOrDefault(x => x.Id == category.CategoryId);

            if (category != null && ModelState.IsValid)
            {
                existingCategory.Name = category.CategoryName;

                this.Data.SaveChanges();
            }

            return Json((new[] { category }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 7
0
        public ActionResult Edit([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            if (ModelState.IsValid)
            {
                var editedCategory = this.Data.Categories.GetById(category.Id);
                editedCategory.Name = category.Name;
                this.Data.Categories.Update(editedCategory);
                this.Data.SaveChanges();
            }
            else
            {
                ModelState.AddModelError("Name", "Category name is invalid!");
            }

            return Json(new[] { category }.ToDataSourceResult(request, ModelState));
        }
        public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            if (ModelState.IsValid)
            {

                Category newCategory = new Category()
                {
                    Name = category.Name
                };

                this.Data.Categories.Add(newCategory);
                this.Data.SaveChanges();
                //category.Id = newCategory.Id;
            }

            return Json(new[] { category }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 9
0
        public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            if (category != null && ModelState.IsValid)
            {
                var newCategory = new Category
                {
                    Id = category.CategoryId,
                    Name = category.CategoryName
                };

                this.Data.Categories.Add(newCategory);
                this.Data.SaveChanges();

                category.CategoryId = newCategory.Id;
            }

            return Json(new[] { category }.ToDataSourceResult(request, ModelState), JsonRequestBehavior.AllowGet);
        }
Ejemplo n.º 10
0
        public JsonResult DeleteCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            var existingCategory = this.Data.Categories.All().FirstOrDefault(x => x.Id == category.CategoryId);

            foreach (var ticket in existingCategory.Tickets.ToList())
            {
                foreach (var comment in ticket.Comments.ToList())
                {
                    this.Data.Comments.Delete(comment);
                }
                this.Data.Tickets.Delete(ticket);
            }

            this.Data.Categories.Delete(existingCategory);

            this.Data.SaveChanges();

            return Json(new[] { category }, JsonRequestBehavior.AllowGet);
        }