public IActionResult Post([FromBody] CategoryDataTransferObject category) { var categoryServiceResult = _categoryService.Add(category); if (categoryServiceResult.ResponseCode != ResponseCode.Success) { return(BadRequest(categoryServiceResult.Error)); } return(Ok(categoryServiceResult.Result)); }
public ServiceResult <CategoryDataTransferObject> Add(CategoryDataTransferObject category) { var categoryEntity = new Category { Description = category.Description }; _categoryRepository.Add(categoryEntity); _categoryRepository.SaveChanges(); category.Id = categoryEntity.Id; return(ServiceResult <CategoryDataTransferObject> .SuccessResult(category)); }