public ActionResult Create(Category category)
        {
            if (ModelState.IsValid)
            {
                context.Categories.Add(category);
                context.SaveChanges();
                return RedirectToAction("Index");
            }

            return View(category);
        }
        public void ContrololerAddShouRedispayIfCategoryInvalid()
        {
            CodeBaseContext repo = new FakeCodeBaseContext();
            CategoriesController controller = new CategoriesController { context = repo };
            controller.ModelState.AddModelError("eror", "model error");
            var c = new Category { CategoryId = 1, Title = "1", Articles = null };
            var result = controller.Create();

            Assert.IsNotNull(result);
            Assert.IsTrue((result as ViewResult).ViewData.ModelState.Count > 0, "Expected errors");
        }
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         context.Entry(category).State = EntityState.Modified;
         context.SaveChanges();
         return RedirectToAction("Index");
     }
     return View(category);
 }