Example #1
0
        private void AddShippingAddressToOwnerPersonIfItIsNew(ProductChild pc)
        {
            Owner productChildOwner = pc.Owner;

            productChildOwner.IsNullThrowException();
            Person ownerPerson = productChildOwner.Person;

            ownerPerson.IsNullThrowException();
            AddressBiz addressBiz = OwnerBiz.AddressBiz;

            //get the address from the productChild
            AddressComplex shipFromAddressComplexInProductChild = pc.ShipFromAddressComplex;

            shipFromAddressComplexInProductChild.ErrorCheck();

            //if there is no address... there should be an error.
            if (!shipFromAddressComplexInProductChild.Error.IsNullOrWhiteSpace())
            {
                throw new Exception("You need to add the address of where the product is sitting");
            }

            //address is complete.
            //We need to make the unique name from this so that we can check it exists in the db
            AddressMain addressToSave = addressBiz.Factory() as AddressMain;

            addressToSave.LoadFor(shipFromAddressComplexInProductChild);
            addressToSave.Name = addressToSave.MakeUniqueName();
            //locate this address in Person

            //get all the addresses for the ownerPerson
            List <AddressMain> allAddressForOwnerPerson = addressBiz.FindAll().Where(x => x.PersonId == ownerPerson.Id).ToList();

            if (allAddressForOwnerPerson.IsNull())
            {
                //no addresses found. Its empty...
                //so add the new address
                addNewAddress(pc, ownerPerson, addressBiz, addressToSave);
            }
            {
                //addresses have been found
                //we do not update old addresses, we just add new ones, if they change.
                AddressMain addressFound = allAddressForOwnerPerson.FirstOrDefault(x => x.Name.ToLower() == addressToSave.Name.ToLower());

                if (addressFound.IsNull())
                {
                    //the address was not found.
                    //AddressComplex contains a new address
                    //Add it to the person's addresses

                    addNewAddress(pc, ownerPerson, addressBiz, addressToSave);
                }
                //else
                //{
                //    updateAddress(pc, addressBiz, addressToSave);
                //}
            }

            //otherwise do nothing
        }
Example #2
0
        /// <summary>
        /// This returns the new address Id, or null.
        /// </summary>
        /// <param name="buySellDoc"></param>
        /// <param name="addressComplex"></param>
        /// <returns></returns>
        private bool isNewAddress(BuySellDoc buySellDoc, AddressComplex addressComplex, out string addressFoundId)
        {
            addressFoundId = "";
            if (addressComplex.IsNull())
            {
                return(false);
            }

            buySellDoc.IsNullThrowException();

            Customer customer = buySellDoc.Customer;

            customer.IsNullThrowException();

            Person person = customer.Person;

            person.IsNullThrowException();

            addressComplex.ErrorCheck();
            //if there is no address... there should be an error.
            if (!addressComplex.Error.IsNullOrWhiteSpace())
            {
                throw new Exception(addressComplex.Error);
            }

            //address is complete.
            //We need to make the unique name from this so that we can check it exists in the db
            AddressMain addressToSave = AddressBiz.Factory() as AddressMain;

            addressToSave.LoadFor(addressComplex);
            addressToSave.Name = addressToSave.MakeUniqueName();

            //locate this address in Person

            //get all the addresses for the ownerPerson
            List <AddressMain> allAddressForOwnerPerson = AddressBiz.FindAll().Where(x => x.PersonId == person.Id).ToList();

            if (allAddressForOwnerPerson.IsNull())
            {
                //no addresses found. Its empty...
                //so add the new address
                return(true);
            }
            else
            {
                //addresses have been found
                //we do not update old addresses, we just add new ones, if they change.
                AddressMain addressFound = allAddressForOwnerPerson.FirstOrDefault(x => x.Name.ToLower() == addressToSave.Name.ToLower());

                if (addressFound.IsNull())
                {
                    //the address was not found.
                    //AddressComplex contains a new address
                    //Add it to the person's addresses

                    return(true);
                }
                else
                {
                    addressFoundId = addressFound.Id;
                }
            }

            return(false);
        }