protected CustomerAccount UserInfoToCustomer(UserInfo uInfo)
        {
            if (uInfo == null)
            {
                throw new ArgumentNullException("uInfo");
            }

            var addressBook        = uInfo.Profile.GetPropertyValue("HccAddressBook") ?? "";
            var billingAddress     = uInfo.Profile.GetPropertyValue("HccBillingAddress") ?? "";
            var shippingAddress    = uInfo.Profile.GetPropertyValue("HccShippingAddress") ?? "";
            var taxExemptString    = uInfo.Profile.GetPropertyValue("HccTaxExempt");
            var taxExempt          = string.IsNullOrEmpty(taxExemptString) ? false : bool.Parse(taxExemptString);
            var taxExemptionNumber = uInfo.Profile.GetPropertyValue("HccTaxExemptionNumber") ?? "";
            var notes          = uInfo.Profile.GetPropertyValue("HccNotes") ?? "";
            var pricingGroupId = uInfo.Profile.GetPropertyValue("HccPricingGroupId") ?? "";

            return(new CustomerAccount
            {
                Bvin = uInfo.UserID.ToString(),
                StoreId = Context.CurrentStore != null ? Context.CurrentStore.Id : 0,
                Username = uInfo.Username,
                Email = uInfo.Email,
                FirstName = uInfo.FirstName,
                LastName = uInfo.LastName,
                Password = string.Empty,
                TaxExempt = taxExempt,
                TaxExemptionNumber = taxExemptionNumber,
                Notes = notes,
                PricingGroupId = pricingGroupId,
                Locked = !uInfo.Membership.Approved,
                LockedUntilUtc = DateTime.UtcNow, // TODO: Remove from CustomerAccount
                FailedLoginCount = 0,             // TODO: Remove from CustomerAccount

                LastUpdatedUtc = uInfo.LastModifiedOnDate.ToUniversalTime(),
                CreationDateUtc = uInfo.CreatedOnDate.ToUniversalTime(),
                LastLoginDateUtc = uInfo.Membership.LastLoginDate.ToUniversalTime(),
                BillingAddress = Json.ObjectFromJson <Address>(billingAddress) ?? new Address(),
                ShippingAddress = Json.ObjectFromJson <Address>(shippingAddress) ?? new Address(),
                Addresses = AddressList.FromJson(addressBook)
            });
        }
Exemplo n.º 2
0
        protected override void CopyDataToModel(hcc_User data, CustomerAccount model)
        {
            model.Bvin             = data.bvin;
            model.StoreId          = data.StoreId;
            model.LastUpdatedUtc   = data.LastUpdated;
            model.CreationDateUtc  = data.CreationDate;
            model.Email            = data.Email;
            model.FailedLoginCount = data.FailedLoginCount;
            model.FirstName        = data.FirstName;
            model.LastLoginDateUtc = data.LastLoginDate;
            model.LastName         = data.LastName;
            model.Locked           = data.Locked == 1;
            model.LockedUntilUtc   = data.LockedUntil;
            model.Notes            = data.Comment;
            model.Password         = data.Password;
            model.PricingGroupId   = data.PricingGroup;
            model.TaxExempt        = data.TaxExempt == 1;

            Address shipAddr = null;
            Address billAddr = null;

            try
            {
                shipAddr        = Json.ObjectFromJson <Address>(data.ShippingAddress);
                billAddr        = Json.ObjectFromJson <Address>(data.BillingAddress);
                model.Addresses = AddressList.FromJson(data.AddressBook);
                model.Phones    = PhoneNumberList.FromJson(data.Phones);
            }
            catch (Exception ex)
            {
                EventLog.LogEvent(ex);
            }
            model.ShippingAddress = shipAddr ?? new Address();

            model.BillingAddress = billAddr ?? new Address();
        }