public IHttpActionResult CreateCategory([FromBody] TestCategoryBindingModel category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestCategoryDTO newCategory = new TestCategoryDTO() { Title = category.Title }; this._testCategoryService.Add(newCategory); return(Ok()); }
public IHttpActionResult UpdateCategory(int id, [FromBody] TestCategoryBindingModel category) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } TestCategoryDTO categoryToUpdate = this._testCategoryService.GetById(id); if (categoryToUpdate == null) { return(Content(HttpStatusCode.NotFound, $"Test category with id={id} does not exist.")); } TestCategoryDTO updatedCategory = new TestCategoryDTO() { Title = category.Title }; this._testCategoryService.Update(updatedCategory); return(Ok()); }