private void DoDependentUpdate(UpdatedPersonDependent updateDependent, PersonDependent dependent, List <EmailAddress> emails) { dependent.DependentTypeId = updateDependent.DependentTypeId; dependent.FirstName = updateDependent.FirstName; dependent.LastName = updateDependent.LastName; dependent.NameSuffix = updateDependent.NameSuffix; dependent.PassportName = updateDependent.PassportName; dependent.PreferredName = updateDependent.PreferredName; dependent.GenderId = updateDependent.GenderId; dependent.DateOfBirth = updateDependent.DateOfBirth; dependent.PlaceOfBirthId = updateDependent.PlaceOfBirthId; dependent.PlaceOfResidenceId = updateDependent.PlaceOfResidenceId; dependent.BirthCountryReasonId = updateDependent.BirthCountryReasonId; dependent.IsTravellingWithParticipant = updateDependent.IsTravellingWithParticipant; dependent.IsDeleted = updateDependent.IsDeleted; updateDependent.Audit.SetHistory(dependent); SetDependentCountriesOfCitizenship(updateDependent.CountriesOfCitizenship, dependent); SetDependentEmails(emails, dependent); }
/// <summary> /// Delete a dependent /// </summary> /// <param name="updatedDependent">The dependent to update/delete</param> /// <returns></returns> public async Task DeleteDependentAsync(UpdatedPersonDependent updatedDependent) { var dependent = await Context.PersonDependents.Where(x => x.DependentId == updatedDependent.DependentId).Include(x => x.CountriesOfCitizenship).Include(x => x.EmailAddresses).FirstOrDefaultAsync(); if (!string.IsNullOrEmpty(dependent.SevisId)) { updatedDependent.IsDeleted = true; var emails = new List <EmailAddress>(); if (!string.IsNullOrEmpty(updatedDependent.EmailAddress)) { emails = await Context.EmailAddresses.Where(x => x.DependentId == updatedDependent.DependentId).ToListAsync(); } DoDependentUpdate(updatedDependent, dependent, emails); } else { DoDelete(dependent); } }
/// <summary> /// Update a person dependent /// </summary> /// <param name="person">The dependent to update</param> /// <returns>The updated dependent</returns> public async Task <PersonDependent> UpdatePersonDependentAsync(UpdatedPersonDependent updatedDependent) { var personToUpdate = await GetPersonDependentModelByIdAsync(updatedDependent.DependentId); var emails = await Context.EmailAddresses.Where(x => x.DependentId == updatedDependent.DependentId).ToListAsync(); if (!string.IsNullOrEmpty(updatedDependent.EmailAddress)) { var email = new EmailAddress { EmailAddressTypeId = EmailAddressType.Personal.Id, Address = updatedDependent.EmailAddress, IsPrimary = true, DependentId = updatedDependent.DependentId }; emails.Clear(); emails.Add(email); } DoDependentUpdate(updatedDependent, personToUpdate, emails); return(personToUpdate); }