Ejemplo n.º 1
0
        public async Task <MedicalRecordResponse> UpdateAsync(int id, MedicalRecord medicalRecord)
        {
            var existingMedicalRecord = await _medicalRecordRepository.FindByIdAsync(id);

            if (existingMedicalRecord == null)
            {
                return(new MedicalRecordResponse("Medical Record not found."));
            }

            existingMedicalRecord.Identifier = medicalRecord.Identifier;
            existingMedicalRecord.PatientId  = medicalRecord.PatientId;

            try
            {
                _medicalRecordRepository.Update(existingMedicalRecord);
                await _unitOfWork.CompleteAsync();

                return(new MedicalRecordResponse(existingMedicalRecord));
            }
            catch (Exception ex)
            {
                // Do some logging stuff
                return(new MedicalRecordResponse($"An error occurred when updating the medical record: {ex.Message}"));
            }
        }