public async Task <Patient> UpdatePatientWithFamily(Patient newPatient) { try { var patientSpecification = new PatientWithFamilySpecification(row => row.Id == newPatient.Id); var oldPatient = await GetPatientWithPatientSpecification(patientSpecification); if (oldPatient == null) { return(null); } _mapper.Map(newPatient, oldPatient); oldPatient.UpdatePatientSiblings(); int results; // Update Parents if (oldPatient.PatientParents != null && oldPatient.PatientParents.Count > 0) { results = await _patientRepository.UpdateAsync(oldPatient); // update Father if (newPatient.Father != null) { var existedFather = await _parentRepository.GetByIdAsync(newPatient.Father.Id); _mapper.Map(newPatient.Father, existedFather as Father); await _parentRepository.UpdateAsync(existedFather); } // update Mother if (newPatient.Mother != null) { var existedMother = await _parentRepository.GetByIdAsync(newPatient.Mother.Id); _mapper.Map(newPatient.Mother, existedMother as Mother); await _parentRepository.UpdateAsync(existedMother); } } // Add new Parents else { oldPatient.AddPatientParents(); results = await _patientRepository.UpdateAsync(oldPatient); } return(results > 0 ? oldPatient : null); } catch (Exception exp) { Console.WriteLine(exp); throw; } }
public async Task <Patient> GetPatientWithFamily(int patientId) { var patientSpecification = new PatientWithFamilySpecification(row => row.Id == patientId); return(await GetPatientWithPatientSpecification(patientSpecification)); }