Created
January 31, 2019 13:42
-
-
Save evgomes/fb05d14fbaca913e749c136cd2a94569 to your computer and use it in GitHub Desktop.
DeleteAsync 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<CategoryResponse> DeleteAsync(int id) | |
{ | |
var existingCategory = await _categoryRepository.FindByIdAsync(id); | |
if (existingCategory == null) | |
return new CategoryResponse("Category not found."); | |
try | |
{ | |
_categoryRepository.Remove(existingCategory); | |
await _unitOfWork.CompleteAsync(); | |
return new CategoryResponse(existingCategory); | |
} | |
catch (Exception ex) | |
{ | |
// Do some logging stuff | |
return new CategoryResponse($"An error occurred when deleting the category: {ex.Message}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment