public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel categoryVM)
        {
            if (categoryVM != null)
            {
                Category category = new Category() { Name = categoryVM.Name };
                this.Data.Categories.Add(category);
                this.Data.SaveChanges();
                categoryVM.Id = category.Id;
            }

            return Json(new[] { categoryVM }.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
        }
        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));
        }
示例#3
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);
        }
        public ActionResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryAdminModel category)
        {
            if (ModelState.IsValid)
            {
                var addedCategory = new Category()
                {
                    Name = category.Name
                };

                this.Data.Categories.Add(addedCategory);

                this.Data.SaveChanges();

                category.Id = addedCategory.Id;
            }

            return Json(new[] { category }.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));
        }