示例#1
0
        /// <summary>
        /// Метод производит проверки при изменении юридического адреса клиента
        /// </summary>
        /// <param name="addressViewModel"></param>
        /// <param name="account"></param>
        /// <returns></returns>
        public Dictionary <string, string> ChangeLegalAddressCheck(AccountAddressViewModel addressViewModel, Account account)
        {
            if (!Enum.TryParse(typeof(AddressType), addressViewModel.CurrentAddressNewType, out object newAddressType))
            {
                errors.Add("AddressTypeWrong", resManager.GetString("AddressTypeWrong"));
                return(errors);
            }

            if ((AddressType)newAddressType == AddressType.Legal)
            {
                errors.Add("AddressTypeWrong", resManager.GetString("AddressTypeWrong"));
                return(errors);
            }

            if (!Guid.TryParse(addressViewModel.NewLegalAddressId, out Guid newLegalAddressId))
            {
                errors.Add("AddressNotFound", resManager.GetString("AddressNotFound"));
                return(errors);
            }

            if (context.AccountAddresses.FirstOrDefault(i => i.Id == newLegalAddressId) == null)
            {
                errors.Add("AddressNotFound", resManager.GetString("AddressNotFound"));
            }
            return(errors);
        }
示例#2
0
        /// <summary>
        /// Метод пытается изменить юридический адрес у клиента
        /// </summary>
        /// <param name="addressViewModel"></param>
        /// <param name="errors"></param>
        /// <returns></returns>
        public bool TryChangeLegalAddress(AccountAddressViewModel addressViewModel, out Dictionary <string, string> errors)
        {
            errors = new Dictionary <string, string>();
            if (!TryGetItemById(addressViewModel.AccountId, out Account account))
            {
                if (!errors.ContainsKey("RecordNotFound"))
                {
                    errors.Add("RecordNotFound", resManager.GetString("RecordNotFound"));
                }
                return(false);
            }

            errors = validator.ChangeLegalAddressCheck(addressViewModel, account);
            if (errors.Any())
            {
                return(false);
            }

            AccountAddress oldLegalAddress = account.GetAddresses(context).FirstOrDefault(addr => addr.AddressType == AddressType.Legal);

            oldLegalAddress.AddressType = (AddressType)Enum.Parse(typeof(AddressType), addressViewModel.CurrentAddressNewType);
            AccountAddress newLegalAddress = context.AccountAddresses.FirstOrDefault(i => i.Id == Guid.Parse(addressViewModel.NewLegalAddressId));

            newLegalAddress.AddressType = AddressType.Legal;
            context.AccountAddresses.UpdateRange(oldLegalAddress, newLegalAddress);
            context.SaveChanges();
            return(true);
        }
示例#3
0
        public AccountIndexViewModel BuildAccountIndexViewModel(AccountViewModel account, Customer customer, UrlHelper urlHelper)
        {
            var billingAddress = new Address();

            billingAddress.LoadByCustomer(customer.CustomerID, customer.PrimaryBillingAddressID, AddressTypes.Billing);

            var primaryBillingAddress = new AccountAddressViewModel
            {
                Id        = billingAddress.AddressID,
                FirstName = billingAddress.FirstName,
                LastName  = billingAddress.LastName,
                Company   = billingAddress.Company,
                Address1  = billingAddress.Address1,
                Address2  = billingAddress.Address2,
                Suite     = billingAddress.Suite,
                City      = billingAddress.City,
                State     = billingAddress.State,
                Zip       = billingAddress.Zip,
                Country   = billingAddress.Country,
                Phone     = billingAddress.Phone
            };

            var shippingAddress = new Address();

            shippingAddress.LoadByCustomer(customer.CustomerID, customer.PrimaryShippingAddressID, AddressTypes.Billing);

            var primaryShippingAddress = new AccountAddressViewModel
            {
                Id        = shippingAddress.AddressID,
                FirstName = shippingAddress.FirstName,
                LastName  = shippingAddress.LastName,
                Company   = shippingAddress.Company,
                Address1  = shippingAddress.Address1,
                Address2  = shippingAddress.Address2,
                Suite     = shippingAddress.Suite,
                City      = shippingAddress.City,
                State     = shippingAddress.State,
                Zip       = shippingAddress.Zip,
                Country   = shippingAddress.Country,
                Phone     = shippingAddress.Phone
            };

            return(new AccountIndexViewModel(
                       account: account,
                       primaryBillingAddress: primaryBillingAddress,
                       primaryShippingAddress: primaryShippingAddress,
                       orders: BuildOrderViewModels(customer, Settings.StoreId),
                       paymentMethodLastUsed: billingAddress.DisplayPaymentMethodInfo(customer, billingAddress.PaymentMethodLastUsed),
                       showWishListButton: Settings.ShowWishlistButtons,
                       showVatRegistrationId: Settings.VatEnabled,
                       showSaveCreditCardNumber: Settings.StoreCreditCards,
                       saveCreditCardNumberNote: Settings.StoreCreditCards &&
                       customer.HasActiveRecurringOrders(true) &&
                       !Settings.UseGatewayInternalBilling
                                                ? "You have recurring orders that require your credit card info to be kept on file. If you uncheck this box, we will be unable to continue processing your recurring orders without contacting you for payment information."
                        : null,
                       showRecurringOrders: ShoppingCart.NumItems(customer.CustomerID, CartTypeEnum.RecurringCart) > 0,
                       showWallets: new AspDotNetStorefrontGateways.Processors.AuthorizeNet().IsCimEnabled,
                       customerLevel: customer.CustomerLevelID != 0
                                        ? customer.CustomerLevelName
                                        : string.Empty,
                       hasMicropayBalance: customer.IsRegistered &&
                       AppLogic.MicropayIsEnabled() &&
                       AppLogic.GetMicroPayProductID() != 0,
                       showMicropayLink: AppLogic.AppConfigBool("MicroPay.ShowAddToBalanceLink") &&
                       AppLogic.MicropayIsEnabled() &&
                       AppLogic.GetMicroPayProductID() != 0,
                       micropayLink: urlHelper.BuildProductLink(AppLogic.GetMicroPayProductID()),
                       micropayBalance: customer.MicroPayBalance,
                       localeSetting: customer.LocaleSetting,
                       currencySetting: customer.CurrencySetting,
                       requireEmailConfirmation: AppLogic.AppConfigBool("RequireEmailConfirmation"),
                       displayOver13Selector: AppLogic.AppConfigBool("RequireOver13Checked")));
        }