Exemple #1
0
 public void AddCategory_Test()
 {
     Assert.AreEqual(3, _categoryLogic.GetAllCategories().Count);
     _categoryLogic.AddCategory(new CategoryDTO()
     {
         CategoryID = 5, Name = "category5"
     });
     Assert.AreEqual(4, _categoryLogic.GetAllCategories().Count);
 }
Exemple #2
0
 public ActionResult Create(Category category)
 {
     if (ModelState.IsValid)
     {
         categoryLogic.AddCategory(category);
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public IHttpActionResult AddCategory([FromBody] CategoryDTO category)
 {
     try
     {
         if (ModelState.IsValid)
         {
             return(Ok(CategoryLogic.AddCategory(category)));
         }
         var errors = ModelState.Select(x => x.Value.Errors)
                      .Where(y => y.Count > 0)
                      .ToList();
         return(BadRequest(errors.ToString()));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }