/// <summary>
        /// Converts the billing address into an order address and saves it. If any changes to the address should be saved for future usage
        /// then the address will also be converted as a customer addresses and gets related to the current contact.
        /// </summary>
        /// <param name="checkoutViewModel">The view model representing the purchase order.</param>
        private void SaveBillingAddress(CheckoutViewModel checkoutViewModel)
        {
            if (!_addressBookService.CanSave(checkoutViewModel.BillingAddress))
            {
                return;
            }

            var orderAddress = _checkoutService.AddNewOrderAddress();

            _addressBookService.MapModelToOrderAddress(checkoutViewModel.BillingAddress, orderAddress);
            orderAddress.Name = Guid.NewGuid().ToString();
            orderAddress.AcceptChanges();
            _checkoutService.UpdateBillingAddressId(orderAddress.Name);

            if (checkoutViewModel.BillingAddress.SaveAddress && User.Identity.IsAuthenticated)
            {
                var currentContact  = _customerContext.CurrentContact.CurrentContact;
                var customerAddress = currentContact.ContactAddresses.FirstOrDefault(x => x.AddressId == checkoutViewModel.BillingAddress.AddressId)
                                      ?? CustomerAddress.CreateInstance();

                _addressBookService.MapModelToCustomerAddress(checkoutViewModel.BillingAddress, customerAddress);

                if (checkoutViewModel.BillingAddress.AddressId == null)
                {
                    currentContact.AddContactAddress(customerAddress);
                }
                else
                {
                    BusinessManager.Update(customerAddress);
                }
                currentContact.SaveChanges();
            }
        }
Example #2
0
        /// <summary>
        /// Converts the billing address into an order address and saves it. If any changes to the address should be saved for future usage
        /// then the address will also be converted as a customer addresses and gets related to the current contact.
        /// </summary>
        /// <param name="checkoutViewModel">The view model representing the purchase order.</param>
        private void SaveBillingAddress(CheckoutViewModel checkoutViewModel)
        {
            var orderAddress = _checkoutService.AddNewOrderAddress();

            _addressBookService.MapModelToOrderAddress(checkoutViewModel.BillingAddress, orderAddress);
            orderAddress.Name = Guid.NewGuid().ToString();
            orderAddress.AcceptChanges();
            _checkoutService.UpdateBillingAddressId(orderAddress.Name);

            SaveToAddressBookIfNeccessary(checkoutViewModel.BillingAddress);
        }