Ejemplo n.º 1
0
        /// <summary>
        /// Adds the customer address.
        /// </summary>
        /// <param name="orderAddress">The order address.</param>
        /// <returns></returns>
        private static void AddCustomerAddress(OrderAddress orderAddress)
        {
            var contact = CustomerContext.Current.GetContactById(SecurityContext.Current.CurrentUserId);

            if (contact == null)
            {
                return;
            }

            var address = contact.ContactAddresses.FirstOrDefault(x => x.Name.Equals(orderAddress.Name));

            if (address == null)
            {
                address              = CustomerAddress.CreateForApplication(AppContext.Current.ApplicationId);
                address.AddressType  = CustomerAddressTypeEnum.Public;
                address.CreatorId    = SecurityContext.Current.CurrentUserId;
                address.Created      = DateTime.Now.ToUniversalTime();
                address.PrimaryKeyId = BusinessManager.Create(address);
                if (!contact.ContactAddresses.Any(x => x.PrimaryKeyId == address.PrimaryKeyId))
                {
                    address.ContactId = contact.PrimaryKeyId;
                }
            }

            address.ModifierId = SecurityContext.Current.CurrentUserId;
            address.Modified   = DateTime.Now.ToUniversalTime();
            OrderAddress.CopyOrderAddressToCustomerAddress(orderAddress, address);
            BusinessManager.Update(address);
        }
Ejemplo n.º 2
0
        public CustomerContact CreateCustomer(string email, string password, string phone, OrderAddress billingAddress,
                                              OrderAddress shippingAddress, bool hasPassword, Action <MembershipCreateStatus> userCreationFailed)
        {
            MembershipCreateStatus createStatus;
            var user = Membership.CreateUser(email, password, email, null, null, true, out createStatus);

            switch (createStatus)
            {
            case MembershipCreateStatus.Success:

                Roles.AddUserToRole(user.UserName, Mediachase.Commerce.Core.AppRoles.EveryoneRole);
                Roles.AddUserToRole(user.UserName, Mediachase.Commerce.Core.AppRoles.RegisteredRole);

                var customer = CustomerContext.Current.GetContactForUser(user);
                customer.FirstName = billingAddress.FirstName;
                customer.LastName  = billingAddress.LastName;
                customer.FullName  = string.Format("{0} {1}", customer.FirstName, customer.LastName);
                customer.SetPhoneNumber(phone);
                customer.SetHasPassword(hasPassword);

                var customerBillingAddress = CustomerAddress.CreateForApplication(Mediachase.Commerce.Core.AppContext.Current.ApplicationId);
                OrderAddress.CopyOrderAddressToCustomerAddress(billingAddress, customerBillingAddress);
                customer.AddContactAddress(customerBillingAddress);
                customer.SaveChanges();
                customer.PreferredBillingAddressId = customerBillingAddress.AddressId;
                customerBillingAddress.Name        = string.Format("{0}, {1} {2}", customerBillingAddress.Line1,
                                                                   customerBillingAddress.PostalCode, customerBillingAddress.City);
                CheckCountryCode(customerBillingAddress);
                BusinessManager.Update(customerBillingAddress);
                customer.SaveChanges();

                var customerShippingAddress = CustomerAddress.CreateForApplication(Mediachase.Commerce.Core.AppContext.Current.ApplicationId);
                OrderAddress.CopyOrderAddressToCustomerAddress(shippingAddress, customerShippingAddress);
                customer.AddContactAddress(customerShippingAddress);
                customer.SaveChanges();
                customer.PreferredShippingAddressId = customerShippingAddress.AddressId;
                customerShippingAddress.Name        = string.Format("{0}, {1} {2}", customerShippingAddress.Line1,
                                                                    customerShippingAddress.PostalCode, customerShippingAddress.City);
                CheckCountryCode(customerShippingAddress);
                BusinessManager.Update(customerShippingAddress);
                customer.SaveChanges();

                return(customer);

            default:
                userCreationFailed(createStatus);
                break;
            }
            return(null);
        }