public override async Task <DeletePreferenceResponse> DeletePreference(DeletePreferenceRequest request, ServerCallContext context) { Preference preference = await _preferenceRepository.Get(x => x.Id == request.Id).FirstOrDefaultAsync(); if (preference == null) { throw new RpcException(new Status(StatusCode.NotFound, $"Preference with ID={request.Id} is not found.")); } _preferenceRepository.Delete(preference); var deleteCount = await _preferenceRepository.SaveChangesAsync(); var response = new DeletePreferenceResponse { Success = deleteCount > 0 }; return(response); }
public bool Delete(int id) { try { var preferenceDto = GetById(id); if (preferenceDto == null) { _logger.LogError($"Preference with id: {id}, hasn't been found in db."); return(false); } Preference preference = _mapper.Map <Preference>(preferenceDto); _repository.Delete(preference); _repository.Save(); return(true); } catch (Exception ex) { _logger.LogError($"Something went wrong inside DeletePreference action: {ex.Message}"); throw new Exception(); } }