public async Task <BaseResponse <Disease> > Handle(DeleteDiseaseCommand request, CancellationToken cancellationToken) { var response = new BaseResponse <Disease> () { ReponseName = nameof(DeleteDiseaseCommand), Content = new List <Disease> () { } }; var entity = await _diseaseRepository.GetOneAsync(p => p.Id == request.Id); if (entity == null) { response.Status = ResponseType.Error; response.Message = $"{nameof(Disease)} not found."; response.Content = null; } else { await _diseaseRepository.DeleteAsync(entity); response.Status = ResponseType.Success; response.Message = $"{nameof(Disease)} deleted successfully."; response.Content.Add(entity); } return(response); }
private async Task SyncDiseasesAsync(Guid userId, List <DiseaseType> diseaseTypes) { var existingDiseases = await diseaseRepository.GetByUserIdAsync(userId); foreach (var disease in existingDiseases) { await diseaseRepository.DeleteAsync(disease); } foreach (var diseaseType in diseaseTypes) { await diseaseRepository.InsertAsync(new Disease { Id = Guid.NewGuid(), DiseaseType = diseaseType, UserId = userId, }); } }
public async Task <int> Delete(Guid id) { var disease = await _diseaseRepository.GetAsync(id); return(await _diseaseRepository.DeleteAsync(disease)); }