/// <summary> /// Update existing profile /// </summary> /// <param name="id"></param> /// <param name="profileDTO"></param> public void UpdateProfileInformation(int id, ProfileDTO profileDTO) { //if profileDTO data is not valid if (profileDTO == null) { throw new ArgumentException(Messages.warning_CannotAddProfileWithNullInformation); } //Create a new profile entity var currentProfile = _profileRepository.Get(id); //Assign updated value to existing profile var updatedProfile = new Profile(); updatedProfile.ProfileId = id; updatedProfile.FirstName = profileDTO.FirstName; updatedProfile.LastName = profileDTO.LastName; updatedProfile.Email = profileDTO.Email; //Update Profile updatedProfile = this.UpdateProfile(currentProfile, updatedProfile); //Update Address List <AddressDTO> lstUpdatedAddressDTO = profileDTO.AddressDTO; List <ProfileAddress> lstCurrentAddress = _profileAddressRepository.GetFiltered(x => x.ProfileId.Equals(id)).ToList(); UpdateAddress(lstUpdatedAddressDTO, lstCurrentAddress, updatedProfile); //Update Phone List <PhoneDTO> lstUpdatedPhoneDTO = profileDTO.PhoneDTO; List <ProfilePhone> lstCurrentPhone = _profilePhoneRepository.GetFiltered(x => x.ProfileId.Equals(id)).ToList(); UpdatePhone(lstUpdatedPhoneDTO, lstCurrentPhone, updatedProfile); }
/// <summary> /// Update existing profile /// </summary> /// <param name="id"></param> /// <param name="profileDTO"></param> public void UpdateProfileInformation(int id, ProfileDTO profileDTO) { if (profileDTO == null) { throw new ArgumentException(Messages.warning_CannotAddProfileWithNullInformation); } Profile currentProfile = _profileRepository.Get(id); // Assign updated value to existing profile var updatedProfile = new Profile { ProfileId = id, FirstName = profileDTO.FirstName, LastName = profileDTO.LastName, Email = profileDTO.Email }; // Update profile updatedProfile = this.UpdateProfile(currentProfile, updatedProfile); // Update Address List <AddressDTO> addresses = profileDTO.AddressDTO; List <ProfileAddress> currentAddresses = _profileAddressRepository.GetFiltered(x => x.ProfileId == id).ToList(); UpdateAddress(addresses, currentAddresses, updatedProfile); // Update Phone List <PhoneDTO> phones = profileDTO.PhoneDTO; List <ProfilePhone> currentPhones = _profilePhoneRepository.GetFiltered(x => x.ProfileId == id).ToList(); UpdatePhone(phones, currentPhones, updatedProfile); }