public static CategoryViewModel CreateFromCategory(Category category)
 {
     return new CategoryViewModel()
     {
         Id = category.Id,
         Name = category.Name
     };
 }
        public JsonResult CreateCategory([DataSourceRequest] DataSourceRequest request, CategoryViewModel categoryModel)
        {
            if (string.IsNullOrWhiteSpace(categoryModel.Name))
            {
                ModelState.AddModelError("Name", "The 'Category Name' field is required");
            }
            else if (categoryModel.Name.Length < 5 || categoryModel.Name.Length > 255)
            {
                ModelState.AddModelError("Name", "The 'Category Name' field must between 5 and 255 characters");
            }
            else
            {
                var newCategory = new Category()
                {
                    Id = Guid.NewGuid(),
                    Name = categoryModel.Name
                };

                this.db.Categories.Add(newCategory);
                this.db.SaveChanges();
            }

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