public async Task SavePatient(PatientDto patientDto) { if (patientDto is null) { throw new ArgumentNullException(nameof(patientDto)); } var validationResult = await _patientValidator.ValidateAsync(patientDto); if (!validationResult.IsValid) { throw new ValidationException(validationResult.ToString(), validationResult.Errors); } var patient = patientDto.Adapt <Patient>(); await _patientRepository.SavePatient(patient); }
public async Task UpdatePatient(int id, PatientDto patientDto) { if (patientDto is null) { throw new ArgumentNullException(nameof(patientDto)); } var validationResult = await _patientValidator.ValidateAsync(patientDto); if (validationResult.IsValid is false) { throw new ValidationException(validationResult.ToString(), validationResult.Errors); } var patient = await _patientRepository.GetPatient(id); if (patient is null) { throw new KeyNotFoundException($"{patientDto.Id}"); } patientDto.Adapt(patient); await _patientRepository.UpdatePatient(patient); }