Created
January 30, 2019 19:04
-
-
Save evgomes/aab855d881ba6ac90fabf499a7fec8b6 to your computer and use it in GitHub Desktop.
UpdateAsync logic from CategoryService, of Supermarket API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<SaveCategoryResponse> UpdateAsync(int id, Category category) | |
{ | |
var existingCategory = await _categoryRepository.FindByIdAsync(id); | |
if (existingCategory == null) | |
return new SaveCategoryResponse("Category not found."); | |
existingCategory.Name = category.Name; | |
try | |
{ | |
_categoryRepository.Update(existingCategory); | |
await _unitOfWork.CompleteAsync(); | |
return new SaveCategoryResponse(existingCategory); | |
} | |
catch (Exception ex) | |
{ | |
// Do some logging stuff | |
return new SaveCategoryResponse($"An error occurred when updating the category: {ex.Message}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment