Skip to content

Instantly share code, notes, and snippets.

@evgomes
Created January 31, 2019 13:42
Show Gist options
  • Save evgomes/fb05d14fbaca913e749c136cd2a94569 to your computer and use it in GitHub Desktop.
Save evgomes/fb05d14fbaca913e749c136cd2a94569 to your computer and use it in GitHub Desktop.
DeleteAsync from CategoryService, of Supermarket API
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