public JsonResult DeleteCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            var existingCategory = Data.Categories.All().FirstOrDefault(c => c.Id == category.Id);

            Data.Categories.Delete(existingCategory);
            Data.SaveChanges();

            return Json(new[] { category }, JsonRequestBehavior.AllowGet);
        }
        public JsonResult UpdateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            var existingCategory = Data.Categories.All().FirstOrDefault(c => c.Id == category.Id);

            if (category != null && ModelState.IsValid)
            {

                existingCategory.Name = category.Name;
                var catalog = Data.Catalogues.All().FirstOrDefault(c => c.Name == category.Catalog);
                if (catalog!=null)
                {
                    existingCategory.Catalogue = catalog;
                }

                Data.SaveChanges();
            }

            return Json((new[] { category }.ToDataSourceResult(request, ModelState)), JsonRequestBehavior.AllowGet);
        }
        public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel category)
        {
            if (category != null && ModelState.IsValid)
            {
                var catalog = Data.Catalogues.All().FirstOrDefault(c => c.Name == category.Catalog);
                var newCategory = new Category
                {
                    Name=category.Name,
                    Catalogue=catalog

                };

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

                category.Id=newCategory.Id;
            }

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