コード例 #1
0
ファイル: Mapping.cs プロジェクト: vanan08/net_cms
        public static ProfileDTO ProfileToProfileDTO(Profile profile, List<AddressType> addressTypes, List<PhoneType> phoneTypes)
        {
            ProfileDTO objProfileDTO = new ProfileDTO();
            objProfileDTO.ProfileId = profile.ProfileId;
            objProfileDTO.FirstName = profile.FirstName;
            objProfileDTO.LastName = profile.LastName;
            objProfileDTO.Email = profile.Email;
            objProfileDTO.AddressDTO = new List<AddressDTO>();
            objProfileDTO.PhoneDTO = new List<PhoneDTO>();

            foreach (var profileAddress in profile.ProfileAddresses)
            {
                AddressDTO objAddressDTO = AddressToAddressDTO(profileAddress.Address);
                objAddressDTO.AddressTypeId = profileAddress.AddressTypeId;
                objProfileDTO.AddressDTO.Add(objAddressDTO);
            }

            foreach (var profilePhone in profile.ProfilePhones)
            {
                PhoneDTO objPhoneDTO = PhoneToPhoneDTO(profilePhone.Phone);
                objPhoneDTO.PhoneTypeId = profilePhone.PhoneTypeId;
                objProfileDTO.PhoneDTO.Add(objPhoneDTO);
            }
            return objProfileDTO;
        }
コード例 #2
0
        /// <summary>
        /// Create a New Profile
        /// </summary>
        /// <param name="firstName"></param>
        /// <param name="lastName"></param>
        /// <param name="email"></param>
        /// <param name="createdBy"></param>
        /// <param name="created"></param>
        /// <param name="updatedBy"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        public static Profile CreateProfile(string firstName, string lastName, string email, string createdBy, DateTime created, string updatedBy, DateTime updated)
        {
            Profile objProfile = new Profile();

            //Set values for Profile
            objProfile.FirstName = firstName;
            objProfile.LastName = lastName;
            objProfile.Email = email;
            objProfile.Created = created;
            objProfile.CreatedBy = createdBy;
            objProfile.Updated = updated;
            objProfile.UpdatedBy = updatedBy;

            return objProfile;
        }
コード例 #3
0
        /// <summary>
        /// Create a New ProfilePhone
        /// </summary>
        /// <param name="profile"></param>
        /// <param name="phone"></param>
        /// <param name="phoneType"></param>
        /// <param name="createdBy"></param>
        /// <param name="created"></param>
        /// <param name="updatedBy"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        public static ProfilePhone CreateProfilePhone(Profile profile, Phone phone, PhoneType phoneType, string createdBy, DateTime created, string updatedBy, DateTime updated)
        {
            ProfilePhone objProfilePhone = new ProfilePhone();

            //Set values for Address
            objProfilePhone.Created = created;
            objProfilePhone.CreatedBy = createdBy;
            objProfilePhone.Updated = updated;
            objProfilePhone.UpdatedBy = updatedBy;

            //Associate Profile for this Profile Phone
            objProfilePhone.ProfileId = profile.ProfileId;
            //Associate Phone for this Profile Phone
            objProfilePhone.PhoneId = phone.PhoneId;
            //Associate PhoneTye for this Profile Phone
            objProfilePhone.PhoneTypeId = phoneType.PhoneTypeId;
            return objProfilePhone;
        }
コード例 #4
0
        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;
        }
コード例 #5
0
        /// <summary>
        /// Update existing Profile
        /// </summary>
        /// <param name="profile"></param>
        Profile UpdateProfile(Profile currentProfile, Profile updatedProfile)
        {
            updatedProfile.Created = currentProfile.Created;
            updatedProfile.CreatedBy = currentProfile.CreatedBy;
            updatedProfile.Updated = DateTime.Now;
            updatedProfile.UpdatedBy = "Updated User";

            var entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(updatedProfile))//if entity is valid save.
            {
                //add profile and commit changes
                _profileRepository.Merge(currentProfile, updatedProfile);
                _profileRepository.UnitOfWork.Commit();
                return updatedProfile;
            }
            else // if not valid throw validation errors
                throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(updatedProfile));
        }
コード例 #6
0
        /// <summary>
        /// Update profile phone
        /// </summary>
        /// <param name="lstUpdatedPhoneDTO"></param>
        /// <param name="lstCurrentPhone"></param>
        void UpdatePhone(List<PhoneDTO> lstUpdatedPhoneDTO, List<ProfilePhone> lstCurrentPhone, Profile profile)
        {
            //if addressDTO data is not valid
            if (lstUpdatedPhoneDTO == null && lstCurrentPhone == null) return;

            #region If user has deleted all existing Phone

            if (lstUpdatedPhoneDTO == null && lstCurrentPhone != null)
            {
                foreach (ProfilePhone profilePhone in lstCurrentPhone)
                {
                    DeleteProfilePhone(profilePhone);
                }
                return;
            }

            #endregion If user has deleted all existing Phone

            #region If user has added new Phone and there was not any existing Phone

            if (lstUpdatedPhoneDTO != null && lstCurrentPhone == null)
            {
                foreach (PhoneDTO phoneDTO in lstUpdatedPhoneDTO)
                {
                    this.SavePhone(phoneDTO, profile);
                }
                return;
            }

            #endregion If user has added new Phone and there was not any existing Phone

            #region if user has updated or Deleted any record

            List<PhoneDTO> lstNewPhone = lstUpdatedPhoneDTO;

            //Check if Phone exist in database
            foreach (ProfilePhone profilePhone in lstCurrentPhone)
            {
                PhoneDTO objPhoneDTO = lstUpdatedPhoneDTO.FirstOrDefault(x => x.PhoneId.Equals(profilePhone.PhoneId));

                if (objPhoneDTO != null)
                {
                    Phone updatedPhone = new Phone();
                    updatedPhone.PhoneId = objPhoneDTO.PhoneId;
                    updatedPhone.Number = objPhoneDTO.Number;
                    UpdatePhone(profilePhone.Phone, updatedPhone);
                    lstNewPhone.Remove(objPhoneDTO);
                }
                else
                {
                    DeleteProfilePhone(profilePhone);
                }
            }

            //Save new address
            foreach (PhoneDTO phoneDTO in lstNewPhone)
            {
                this.SavePhone(phoneDTO, profile);
            }

            #endregion if user has updated or Deleted any record
        }
コード例 #7
0
        /// <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
        }
コード例 #8
0
        /// <summary>
        /// Save Profile
        /// </summary>
        /// <param name="profile"></param>
        Profile SaveProfile(Profile profile)
        {
            var entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(profile))//if entity is valid save.
            {
                //add profile and commit changes
                _profileRepository.Add(profile);
                _profileRepository.UnitOfWork.Commit();
                return profile;
            }
            else // if not valid throw validation errors
                throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(profile));
        }
コード例 #9
0
        /// <summary>
        /// Add new phone
        /// </summary>
        /// <param name="phoneDTO"></param>
        /// <param name="profile"></param>
        void SavePhone(PhoneDTO phoneDTO, Profile profile)
        {
            //if phoneDTO data is not valid
            if (phoneDTO == null)
                throw new ArgumentException(Messages.warning_CannotAddProfileWithNullInformation);

            //Create a new Phone entity
            var newPhone = PhoneFactory.CreatePhone(phoneDTO.Number, "Anand", DateTime.Now, "Anand", DateTime.Now);

            //Save new Phone
            newPhone = SavePhone(newPhone);

            var phoneType = _phoneTypeRepository.Get(phoneDTO.PhoneTypeId);

            //Create a new Profile Phone entity
            var newProfilePhone = ProfilePhoneFactory.CreateProfilePhone(profile, newPhone, phoneType, "Anand", DateTime.Now, "Anand", DateTime.Now);

            //Save new Profile Phone
            SaveProfilePhone(newProfilePhone);
        }
コード例 #10
0
        /// <summary>
        /// Add new address
        /// </summary>
        /// <param name="addressDTO"></param>
        /// <param name="profile"></param>
        void SaveAddress(AddressDTO addressDTO, Profile profile)
        {
            //if addressDTO data is not valid
            if (addressDTO == null)
                throw new ArgumentException(Messages.warning_CannotAddProfileWithNullInformation);

            //Create a new Address entity
            var newAddress = AddressFactory.CreateAddress(addressDTO.AddressLine1, addressDTO.AddressLine2, addressDTO.City, addressDTO.State, addressDTO.Country,
                                                          addressDTO.ZipCode, "Anand", DateTime.Now, "Anand", DateTime.Now);
            //Save new Address
            SaveAddress(newAddress);

            var addressType = _addressTypeRepository.Get(addressDTO.AddressTypeId);

            //Create a new Profile Address entity
            var newProfileAddress = ProfileAddressFactory.ProfileAddress(profile, newAddress, addressType, "Anand", DateTime.Now, "Anand", DateTime.Now);

            //Save new Address
            SaveProfileAddress(newProfileAddress);
        }
コード例 #11
0
        /// <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);
        }
コード例 #12
0
        /// <summary>
        /// Associate existing Profile to this ProfilePhone
        /// </summary>
        /// <param name="profile"></param>
        public void AssociateProfileForThisProfilePhone(Profile profile)
        {
            if (profile == null)
            {
                throw new ArgumentException(Messages.exception_ProfilePhoneCannotAssociateNullProfile);
            }

            //fix relation
            this.ProfileId = profile.ProfileId;

            this.Profile = profile;
        }