public async Task<IHttpActionResult> PutCategory(CategoryDTO categoryDTO) { if (!ModelState.IsValid) { return BadRequest(ModelState); } Category category = new Category() { Id = categoryDTO.Id, Name = categoryDTO.Name, Description = categoryDTO.Description }; _unitOfWork.CategoryRepository.Update(category); try { await _unitOfWork.CommitAsync(); } catch (DbBusinessException ex) { ModelState.AddModelError("customMessage", ex.Message); return BadRequest(ModelState); } catch (Exception) { ModelState.AddModelError("customMessage", ErrorMessages.GenericErrorMessage); return BadRequest(ModelState); } categoryDTO.Id = category.Id; return Ok(category); }
public async Task<IHttpActionResult> GetCategoty(int id) { Category category = await _unitOfWork.CategoryRepository.GetByIdAsync(id); if (category == null) { return NotFound(); } CategoryDTO categoryDTO = new CategoryDTO() { Id = category.Id, Name = category.Name, Description = category.Description }; return Ok(categoryDTO); }