/// <summary>
        /// Import customer list from XLS file
        /// </summary>
        /// <param name="filePath">Excel file path</param>
        public void ImportCustomersFromXls(string filePath)
        {
            using (ExcelHelper excelHelper = new ExcelHelper(filePath))
            {
                excelHelper.Hdr  = "YES";
                excelHelper.Imex = "1";

                DataTable dt = excelHelper.ReadTable("Customers");
                foreach (DataRow dr in dt.Rows)
                {
                    //int customerId = Convert.ToInt32(dr["CustomerId"]);
                    Guid     customerGuid          = new Guid(dr["CustomerGuid"].ToString());
                    string   email                 = dr["Email"].ToString();
                    string   username              = dr["Username"].ToString();
                    string   passwordHash          = dr["PasswordHash"].ToString();
                    string   saltKey               = dr["SaltKey"].ToString();
                    int      affiliateId           = Convert.ToInt32(dr["AffiliateId"]);
                    int      billingAddressId      = 0;
                    int      shippingAddressId     = 0;
                    int      lastPaymentMethodId   = 0;
                    string   lastAppliedCouponCode = string.Empty;
                    int      languageId            = Convert.ToInt32(dr["LanguageId"]);
                    int      currencyId            = Convert.ToInt32(dr["CurrencyId"]);
                    int      taxDisplayTypeId      = Convert.ToInt32(dr["TaxDisplayTypeId"]);
                    bool     isTaxExempt           = Convert.ToBoolean(dr["IsTaxExempt"]);
                    bool     isAdmin               = Convert.ToBoolean(dr["IsAdmin"]);
                    bool     isGuest               = Convert.ToBoolean(dr["IsGuest"]);
                    bool     isForumModerator      = Convert.ToBoolean(dr["IsForumModerator"]);
                    int      totalForumPosts       = Convert.ToInt32(dr["TotalForumPosts"]);
                    string   signature             = dr["Signature"].ToString();
                    string   adminComment          = dr["AdminComment"].ToString();
                    bool     active                = Convert.ToBoolean(dr["Active"]);
                    bool     deleted               = Convert.ToBoolean(dr["Deleted"]);
                    DateTime registrationDate      = DateTime.FromOADate(Convert.ToDouble(dr["RegistrationDate"]));
                    string   timeZoneId            = dr["TimeZoneId"].ToString();
                    int      avatarId              = Convert.ToInt32(dr["AvatarId"]);

                    //custom properties
                    string gender    = dr["Gender"].ToString();
                    string firstName = dr["FirstName"].ToString();
                    string lastName  = dr["LastName"].ToString();
                    string company   = dr["Company"].ToString();
                    string vatNumber = dr["VatNumber"].ToString();
                    VatNumberStatusEnum vatNumberStatus = (VatNumberStatusEnum)Convert.ToInt32(dr["VatNumberStatus"]);
                    string streetAddress     = dr["StreetAddress"].ToString();
                    string streetAddress2    = dr["StreetAddress2"].ToString();
                    string zipPostalCode     = dr["ZipPostalCode"].ToString();
                    string city              = dr["City"].ToString();
                    string phoneNumber       = dr["PhoneNumber"].ToString();
                    string faxNumber         = dr["FaxNumber"].ToString();
                    int    countryId         = Convert.ToInt32(dr["CountryId"]);
                    int    stateProvinceId   = Convert.ToInt32(dr["StateProvinceId"]);
                    bool   receiveNewsletter = Convert.ToBoolean(dr["ReceiveNewsletter"]);


                    var customer = IoC.Resolve <ICustomerService>().GetCustomerByEmail(email);
                    if (customer == null)
                    {
                        //no customers found
                        customer = IoC.Resolve <ICustomerService>().AddCustomerForced(customerGuid, email, username,
                                                                                      passwordHash, saltKey, affiliateId, billingAddressId, shippingAddressId, lastPaymentMethodId,
                                                                                      lastAppliedCouponCode, string.Empty, string.Empty,
                                                                                      languageId, currencyId, (TaxDisplayTypeEnum)taxDisplayTypeId, isTaxExempt,
                                                                                      isAdmin, isGuest, isForumModerator, totalForumPosts, signature,
                                                                                      adminComment, active, deleted, registrationDate, timeZoneId, avatarId, null);
                    }
                    else
                    {
                        if (!customer.IsGuest)
                        {
                            //customer is not a guest
                            customer.Email                 = email;
                            customer.Username              = username;
                            customer.PasswordHash          = passwordHash;
                            customer.SaltKey               = saltKey;
                            customer.AffiliateId           = affiliateId;
                            customer.BillingAddressId      = billingAddressId;
                            customer.ShippingAddressId     = shippingAddressId;
                            customer.LastPaymentMethodId   = lastPaymentMethodId;
                            customer.LastAppliedCouponCode = lastAppliedCouponCode;
                            customer.LanguageId            = languageId;
                            customer.CurrencyId            = currencyId;
                            customer.TaxDisplayTypeId      = taxDisplayTypeId;
                            customer.IsTaxExempt           = isTaxExempt;
                            customer.IsAdmin               = isAdmin;
                            customer.IsGuest               = isGuest;
                            customer.IsForumModerator      = isForumModerator;
                            customer.TotalForumPosts       = totalForumPosts;
                            customer.Signature             = signature;
                            customer.AdminComment          = adminComment;
                            customer.Active                = active;
                            customer.Deleted               = deleted;
                            customer.RegistrationDate      = registrationDate;
                            customer.TimeZoneId            = timeZoneId;
                            customer.AvatarId              = avatarId;
                            IoC.Resolve <ICustomerService>().UpdateCustomer(customer);
                        }
                        else
                        {
                            //customer is a guest
                            customer = IoC.Resolve <ICustomerService>().GetCustomerByGuid(customerGuid);
                            if (customer == null)
                            {
                                customer = IoC.Resolve <ICustomerService>().AddCustomerForced(customerGuid, email, username,
                                                                                              passwordHash, saltKey, affiliateId, billingAddressId, shippingAddressId, lastPaymentMethodId,
                                                                                              lastAppliedCouponCode, string.Empty,
                                                                                              string.Empty, languageId, currencyId,
                                                                                              (TaxDisplayTypeEnum)taxDisplayTypeId, isTaxExempt,
                                                                                              isAdmin, isGuest, isForumModerator, totalForumPosts, signature,
                                                                                              adminComment, active, deleted, registrationDate, timeZoneId, avatarId, null);
                            }
                            else
                            {
                                customer.Email                 = email;
                                customer.Username              = username;
                                customer.PasswordHash          = passwordHash;
                                customer.SaltKey               = saltKey;
                                customer.AffiliateId           = affiliateId;
                                customer.BillingAddressId      = billingAddressId;
                                customer.ShippingAddressId     = shippingAddressId;
                                customer.LastPaymentMethodId   = lastPaymentMethodId;
                                customer.LastAppliedCouponCode = lastAppliedCouponCode;
                                customer.LanguageId            = languageId;
                                customer.CurrencyId            = currencyId;
                                customer.TaxDisplayTypeId      = taxDisplayTypeId;
                                customer.IsTaxExempt           = isTaxExempt;
                                customer.IsAdmin               = isAdmin;
                                customer.IsGuest               = isGuest;
                                customer.IsForumModerator      = isForumModerator;
                                customer.TotalForumPosts       = totalForumPosts;
                                customer.Signature             = signature;
                                customer.AdminComment          = adminComment;
                                customer.Active                = active;
                                customer.Deleted               = deleted;
                                customer.RegistrationDate      = registrationDate;
                                customer.TimeZoneId            = timeZoneId;
                                customer.AvatarId              = avatarId;

                                IoC.Resolve <ICustomerService>().UpdateCustomer(customer);
                            }
                        }
                    }

                    if (IoC.Resolve <ICustomerService>().FormFieldGenderEnabled)
                    {
                        customer.Gender = gender;
                    }
                    customer.FirstName = firstName;
                    customer.LastName  = lastName;
                    if (IoC.Resolve <ICustomerService>().FormFieldCompanyEnabled)
                    {
                        customer.Company = company;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldStreetAddressEnabled)
                    {
                        customer.StreetAddress = streetAddress;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldStreetAddress2Enabled)
                    {
                        customer.StreetAddress2 = streetAddress2;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldPostCodeEnabled)
                    {
                        customer.ZipPostalCode = zipPostalCode;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldCityEnabled)
                    {
                        customer.City = city;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldPhoneEnabled)
                    {
                        customer.PhoneNumber = phoneNumber;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldFaxEnabled)
                    {
                        customer.FaxNumber = faxNumber;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldCountryEnabled)
                    {
                        customer.CountryId = countryId;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldStateEnabled)
                    {
                        customer.StateProvinceId = stateProvinceId;
                    }
                    if (IoC.Resolve <ICustomerService>().FormFieldNewsletterEnabled)
                    {
                        customer.ReceiveNewsletter = receiveNewsletter;
                    }

                    if (IoC.Resolve <ITaxService>().EUVatEnabled)
                    {
                        customer.VatNumber       = vatNumber;
                        customer.VatNumberStatus = vatNumberStatus;
                    }
                }
            }
        }
예제 #2
0
 /// <summary>
 /// Gets VAT Number status name
 /// </summary>
 /// <param name="status">VAT Number status</param>
 /// <returns>VAT Number status name</returns>
 public static string GetVatNumberStatusName(VatNumberStatusEnum status)
 {
     return LocalizationManager.GetLocaleResourceString(string.Format("VatNumberStatus.{0}", status.ToString()));
 }