示例#1
0
        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);
        }
示例#2
0
        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);
        }