/// <summary> /// Associate existing Address to this ProfileAddress /// </summary> /// <param name="address"></param> public void AssociateAddressForThisProfileAddress(Address address) { if (address == null) { throw new ArgumentException(Messages.exception_ProfileAddressCannotAssociateNullAddress); } //fix relation this.AddressId = address.AddressId; this.Address = address; }
public static AddressDTO AddressToAddressDTO(Address address) { AddressDTO objAddressDTO = new AddressDTO(); if (address != null) { objAddressDTO.AddressId = address.AddressId; objAddressDTO.AddressLine1 = address.AddressLine1; objAddressDTO.AddressLine2 = address.AddressLine2; objAddressDTO.ZipCode = address.ZipCode; objAddressDTO.Country = address.Country; objAddressDTO.State = address.State; objAddressDTO.City = address.City; } return objAddressDTO; }
/// <summary> /// Create a New Address /// </summary> /// <param name="line1"></param> /// <param name="line2"></param> /// <param name="city"></param> /// <param name="zipCode"></param> /// <param name="createdBy"></param> /// <param name="created"></param> /// <param name="updatedBy"></param> /// <param name="updated"></param> /// <returns></returns> public static Address CreateAddress(string line1, string line2, string city, string state, string country, string zipCode, string createdBy, DateTime created, string updatedBy, DateTime updated) { Address objAddress = new Address(); //Set values for Address objAddress.AddressLine1 = line1; objAddress.AddressLine2 = line2; objAddress.Country = country; objAddress.State = state; objAddress.City = city; objAddress.ZipCode = zipCode; objAddress.Created = created; objAddress.CreatedBy = createdBy; objAddress.Updated = updated; objAddress.UpdatedBy = updatedBy; return objAddress; }
public static ProfileAddress ProfileAddress(Profile profile, Address address, AddressType addressType, string createdBy, DateTime created, string updatedBy, DateTime updated) { ProfileAddress objProfileAddress = new ProfileAddress(); //Set values for Address objProfileAddress.Created = created; objProfileAddress.CreatedBy = createdBy; objProfileAddress.Updated = updated; objProfileAddress.UpdatedBy = updatedBy; //Associate Profile for this Profile Phone objProfileAddress.ProfileId = profile.ProfileId; //Associate Address for this Profile Phone objProfileAddress.AddressId = address.AddressId; //Associate AddressTye for this Profile Phone objProfileAddress.AddressTypeId = addressType.AddressTypeId; return objProfileAddress; }
/// <summary> /// Update existing Address /// </summary> /// <param name="profile"></param> void UpdateAddress(Address currentAddress, Address updatedAddress) { updatedAddress.Created = currentAddress.Created; updatedAddress.CreatedBy = currentAddress.CreatedBy; updatedAddress.Updated = DateTime.Now; updatedAddress.UpdatedBy = "Updated User"; var entityValidator = EntityValidatorFactory.CreateValidator(); if (entityValidator.IsValid(updatedAddress))//if entity is valid save. { //add profile and commit changes _addressRepository.Merge(currentAddress, updatedAddress); _addressRepository.UnitOfWork.Commit(); } else // if not valid throw validation errors throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(updatedAddress)); }
/// <summary> /// Update profile address /// </summary> /// <param name="lstUpdatedAddressDTO"></param> /// <param name="lstCurrentAddress"></param> void UpdateAddress(List<AddressDTO> lstUpdatedAddressDTO, List<ProfileAddress> lstCurrentAddress, Profile profile) { //if addressDTO data is not valid if (lstUpdatedAddressDTO == null && lstCurrentAddress == null) return; #region If user has deleted all existing address if (lstUpdatedAddressDTO == null && lstCurrentAddress != null) { foreach (ProfileAddress profileAddress in lstCurrentAddress) { DeleteProfileAddress(profileAddress); } return; } #endregion If user has deleted all existing address #region If user has added new address and there was not any existing address if (lstUpdatedAddressDTO != null && lstCurrentAddress == null) { foreach (AddressDTO addressDTO in lstUpdatedAddressDTO) { this.SaveAddress(addressDTO, profile); } return; } #endregion If user has added new address and there was not any existing address #region if user has updated or Deleted any record List<AddressDTO> lstNewAddress = lstUpdatedAddressDTO; //Check if address exist in database foreach (ProfileAddress profileAddress in lstCurrentAddress) { AddressDTO objAddressDTO = lstUpdatedAddressDTO.FirstOrDefault(x => x.AddressId.Equals(profileAddress.AddressId)); if (objAddressDTO != null) { Address updatedAddress = new Address(); updatedAddress.AddressId = objAddressDTO.AddressId; updatedAddress.AddressLine1 = objAddressDTO.AddressLine1; updatedAddress.AddressLine2 = objAddressDTO.AddressLine2; updatedAddress.City = objAddressDTO.City; updatedAddress.State = objAddressDTO.State; updatedAddress.Country = objAddressDTO.Country; updatedAddress.ZipCode = objAddressDTO.ZipCode; UpdateAddress(profileAddress.Address, updatedAddress); lstNewAddress.Remove(objAddressDTO); } else { DeleteProfileAddress(profileAddress); } } //Save new address foreach (AddressDTO addressDTO in lstNewAddress) { this.SaveAddress(addressDTO, profile); } #endregion if user has updated or Deleted any record }
/// <summary> /// Save Address /// </summary> /// <param name="address"></param> Address SaveAddress(Address address) { var entityValidator = EntityValidatorFactory.CreateValidator(); if (entityValidator.IsValid(address)) //if entity is valid save { //add address and commit changes _addressRepository.Add(address); _addressRepository.UnitOfWork.Commit(); return address; } else //if not valid, throw validation errors throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(address)); }