예제 #1
0
        private void InflateManageAutoOrderViewModel(int customerID, IMarket market, IOrderConfiguration configuration, ref ManageAutoOrderViewModel viewModel)
        {
            viewModel.AvailableStartDates = Enumerable.Range(1, 27).Select(day =>
            {
                var date = new DateTime(DateTime.Now.Year, DateTime.Now.Month, day).BeginningOfDay();
                if (date < DateTime.Now.BeginningOfDay())
                {
                    date = date.AddMonths(1);
                }

                return(date);
            }).OrderBy(d => d.Day).ToList();

            viewModel.AvailableProducts = ExigoDAL.GetItems(new ExigoService.GetItemsRequest()
            {
                Configuration             = configuration,
                LanguageID                = CurrentLanguage.LanguageID,
                CategoryID                = configuration.CategoryID,
                PriceTypeID               = PriceTypes.Wholesale,
                IncludeAllChildCategories = true,
                IncludeDynamicKitChildren = false
            }).ToList();

            viewModel.AvailablePaymentMethods = ExigoDAL.GetCustomerPaymentMethods(customerID)
                                                .Where(p => p.IsValid)
                                                .Where(p => p is IAutoOrderPaymentMethod)
                                                .ToList();

            if (viewModel.AvailablePaymentMethods != null && viewModel.AvailablePaymentMethods.Count() == 1)
            {
                viewModel.NewCreditCard.Type = CreditCardType.Secondary;
            }
        }
        public ActionResult PaymentMethodList()
        {
            var model = ExigoDAL.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest
            {
                CustomerID = Identity.Customer.CustomerID,
                ExcludeIncompleteMethods = true
            });

            return(View(model));
        }
        public ActionResult ManageCreditCard(CreditCardType type)
        {
            var model = ExigoDAL.GetCustomerPaymentMethods(Identity.Customer.CustomerID)
                        .Where(c => c is CreditCard && ((CreditCard)c).Type == type)
                        .FirstOrDefault();

            // Clear out the card number
            ((CreditCard)model).CardNumber = "";

            return(View("ManageCreditCard", model));
        }
        public ActionResult ManageBankAccount(ExigoService.BankAccountType type)
        {
            var model = ExigoDAL.GetCustomerPaymentMethods(Identity.Customer.CustomerID)
                        .Where(c => c is BankAccount && ((BankAccount)c).Type == type)
                        .FirstOrDefault();


            // Clear out the account number
            ((BankAccount)model).AccountNumber = "";


            return(View("ManageBankAccount", model));
        }
예제 #5
0
        public ActionResult ManageAutoOrder(int id, ManageAutoOrderViewModel viewModel)
        {
            var customerID  = Identity.Customer.CustomerID;
            var apiRequests = new List <ApiRequest>();
            var customer    = Customers.GetCustomer(customerID);
            var market      = GlobalSettings.Markets.AvailableMarkets.Where(c => c.Countries.Contains(Identity.Customer.Country)).FirstOrDefault();

            if (market == null)
            {
                market = GlobalSettings.Markets.AvailableMarkets.FirstOrDefault(v => v.IsDefault);
            }
            var configuration       = market.GetConfiguration().AutoOrders;
            var warehouseID         = configuration.WarehouseID;
            var isExistingAutoOrder = id != 0;
            var paymentMethods      = ExigoDAL.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest()
            {
                CustomerID = Identity.Customer.CustomerID, ExcludeIncompleteMethods = true
            });



            // Remove all items that have no quantity.
            viewModel.AutoOrder.Details = viewModel.AutoOrder.Details.Where(d => d.Quantity > 0).ToList();
            if (!viewModel.AutoOrder.Details.Any())
            {
                ModelState.AddModelError("Result", "Please select at least one product for your Auto Order.");
            }



            if (ModelState.Keys.Contains("Result"))
            {
                InflateManageAutoOrderViewModel(customerID, market, configuration, ref viewModel);

                return(View(viewModel));
            }

            // Save New Credit Card
            var isUsingNewCard = viewModel.AutoOrder.AutoOrderPaymentTypeID == 0;
            var hasPrimaryCard = paymentMethods.Where(v => v.IsComplete).Count() > 0;

            if (isUsingNewCard)
            {
                var saveCCRequest = new SetAccountCreditCardTokenRequest(viewModel.NewCreditCard);

                // If there is one or more available payment type, save the card in the secondary card slot
                if (hasPrimaryCard)
                {
                    saveCCRequest.CreditCardAccountType        = AccountCreditCardType.Secondary;
                    viewModel.AutoOrder.AutoOrderPaymentTypeID = AutoOrderPaymentTypes.SecondaryCreditCardOnFile;
                }
                else
                {
                    viewModel.AutoOrder.AutoOrderPaymentTypeID = AutoOrderPaymentTypes.PrimaryCreditCardOnFile;
                }
                saveCCRequest.CustomerID = customerID;
                apiRequests.Add(saveCCRequest);
            }


            // Prepare the auto order
            var autoOrder = viewModel.AutoOrder;
            var createAutoOrderRequest = new CreateAutoOrderRequest(autoOrder)
            {
                PriceType   = configuration.PriceTypeID,
                WarehouseID = warehouseID,
                Notes       = !string.IsNullOrEmpty(autoOrder.Notes)
                                ? autoOrder.Notes
                                : string.Format("Created with the API Auto-Delivery manager at \"{0}\" on {1:u} at IP {2} using {3} {4} ({5}).",
                                                Request.Url.AbsoluteUri,
                                                DateTime.Now.ToUniversalTime(),
                                                GlobalUtilities.GetClientIP(),
                                                HttpContext.Request.Browser.Browser,
                                                HttpContext.Request.Browser.Version,
                                                HttpContext.Request.Browser.Platform),
                CustomerID = customerID
            };

            apiRequests.Add(createAutoOrderRequest);

            try
            {
                // Process the transaction
                var transaction = new TransactionalRequest {
                    TransactionRequests = apiRequests.ToArray()
                };
                var response = ExigoDAL.WebService().ProcessTransaction(transaction);

                return(RedirectToAction("AutoOrderList", new { success = "1" }));
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Result", "We were unable to save your Auto-Delivery: " + ex.Message);

                InflateManageAutoOrderViewModel(customerID, market, configuration, ref viewModel);

                return(View(viewModel));
            }
        }