public void Update(TestCategoryDTO entity) { TestCategory category = _mapper.Map <TestCategory>(entity); _unitOfWork.TestCategories.Update(category); _unitOfWork.SaveChanges(); }
public IHttpActionResult DeleteCategory(int id) { TestCategoryDTO categoryToDel = this._testCategoryService.GetById(id); if (categoryToDel == null) { return(Content(HttpStatusCode.NotFound, $"Test category with id={id} does not exist.")); } this._testCategoryService.Delete(id); return(Ok()); }
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()); }