Example #1
0
 public static PhoneDTO PhoneToPhoneDTO(Phone phone)
 {
     PhoneDTO objPhoneDTO = new PhoneDTO();
     if (phone != null)
     {
         objPhoneDTO.PhoneId = phone.PhoneId;
         objPhoneDTO.Number = phone.Number;
     }
     return objPhoneDTO;
 }
        /// <summary>
        /// Associate existing Phone to this ProfilePhone
        /// </summary>
        /// <param name="phone"></param>
        public void AssociatePhoneForThisProfilePhone(Phone phone)
        {
            if (phone == null)
            {
                throw new ArgumentException(Messages.exception_ProfilePhoneCannotAssociateNullPhone);
            }

            //fix relation
            this.PhoneId = phone.PhoneId;

            this.Phone = phone;
        }
Example #3
0
        /// <summary>
        /// Create a New Phone
        /// </summary>
        /// <param name="number"></param>
        /// <param name="createdBy"></param>
        /// <param name="created"></param>
        /// <param name="updatedBy"></param>
        /// <param name="updated"></param>
        /// <returns></returns>
        public static Phone CreatePhone(string number, string createdBy, DateTime created, string updatedBy, DateTime updated)
        {
            Phone objPhone = new Phone();

            //Set values for Phone
            objPhone.Number = number;
            objPhone.Created = created;
            objPhone.CreatedBy = createdBy;
            objPhone.Updated = updated;
            objPhone.UpdatedBy = updatedBy;

            return objPhone;
        }
Example #4
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;
        }
        /// <summary>
        /// Update existing Phone
        /// </summary>
        /// <param name="currentPhone"></param>
        /// <param name="updatedPhone"></param>
        void UpdatePhone(Phone currentPhone, Phone updatedPhone)
        {
            updatedPhone.Created = currentPhone.Created;
            updatedPhone.CreatedBy = currentPhone.CreatedBy;
            updatedPhone.Updated = DateTime.Now;
            updatedPhone.UpdatedBy = "Updated User";

            var entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(updatedPhone))//if entity is valid save.
            {
                //add profile and commit changes
                _phoneRepository.Merge(currentPhone, updatedPhone);
                _phoneRepository.UnitOfWork.Commit();
            }
            else // if not valid throw validation errors
                throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(updatedPhone));
        }
        /// <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
        }
        /// <summary>
        /// Save Phone
        /// </summary>
        /// <param name="phone"></param>
        Phone SavePhone(Phone phone)
        {
            var entityValidator = EntityValidatorFactory.CreateValidator();

            if (entityValidator.IsValid(phone)) //if entity is valid save
            {
                //add phone and commit changes
                _phoneRepository.Add(phone);
                _phoneRepository.UnitOfWork.Commit();
                return phone;
            }
            else //if not valid, throw validation errors
                throw new ApplicationValidationErrorsException(entityValidator.GetInvalidMessages(phone));
        }