public CreateAutoOrderRequest(Common.Api.ExigoOData.AutoOrder autoOrder)
        {
            var model = new CreateAutoOrderRequest();

            if (autoOrder == null)
            {
                return;
            }

            CustomerID                 = autoOrder.CustomerID;
            ExistingAutoOrderID        = autoOrder.AutoOrderID;
            OverwriteExistingAutoOrder = true;

            Frequency    = Exigo.GetFrequencyType(autoOrder.FrequencyTypeID);
            StartDate    = autoOrder.StartDate;
            StopDate     = autoOrder.StopDate;
            CurrencyCode = autoOrder.CurrencyCode;
            WarehouseID  = autoOrder.WarehouseID;
            ShipMethodID = autoOrder.ShipMethodID;
            PriceType    = PriceTypes.Wholesale;
            PaymentType  = Exigo.GetAutoOrderPaymentType(autoOrder.AutoOrderPaymentTypeID);
            ProcessType  = Exigo.GetAutoOrderProcessType(autoOrder.AutoOrderProcessTypeID);
            Details      = autoOrder.Details.Select(c => new OrderDetailRequest()
            {
                ItemCode                         = c.ItemCode,
                Quantity                         = c.Quantity,
                ParentItemCode                   = c.ParentItemCode,
                BusinessVolumeEachOverride       = c.BusinessVolumeEachOverride,
                CommissionableVolumeEachOverride = c.CommissionableVolumeEachOverride,
                DescriptionOverride              = c.ItemDescription,
                PriceEachOverride                = c.PriceEachOverride,
                ShippingPriceEachOverride        = c.ShippingPriceEachOverride,
                TaxableEachOverride              = c.TaxableEachOverride
            }).ToArray();

            FirstName = autoOrder.FirstName;
            LastName  = autoOrder.LastName;
            Company   = autoOrder.Company;
            Address1  = autoOrder.Address1;
            Address2  = autoOrder.Address2;
            City      = autoOrder.City;
            State     = autoOrder.State;
            Zip       = autoOrder.Zip;
            Country   = autoOrder.Country;
            Email     = autoOrder.Email;
            Phone     = autoOrder.Phone;

            Notes       = autoOrder.Notes;
            Other11     = autoOrder.Other11;
            Other12     = autoOrder.Other12;
            Other13     = autoOrder.Other13;
            Other14     = autoOrder.Other14;
            Other15     = autoOrder.Other15;
            Other16     = autoOrder.Other16;
            Other17     = autoOrder.Other17;
            Other18     = autoOrder.Other18;
            Other19     = autoOrder.Other19;
            Other20     = autoOrder.Other20;
            Description = autoOrder.AutoOrderDescription;
        }
        public ActionResult SubmitCheckout()
        {
            if (!PropertyBag.IsSubmitting)
            {
                PropertyBag.IsSubmitting = true;
                _propertyBag             = Exigo.PropertyBags.Update(PropertyBag);

                try
                {
                    // Start creating the API requests
                    var details = new List <ApiRequest>();


                    // Create the order request, if applicable
                    var orderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order);
                    var hasOrder   = orderItems.Count() > 0;

                    if (hasOrder)
                    {
                        var orderRequest = new CreateOrderRequest(OrderConfiguration, PropertyBag.ShipMethodID, orderItems, PropertyBag.ShippingAddress)
                        {
                            CustomerID = Identity.Current.CustomerID
                        };
                        details.Add(orderRequest);
                    }


                    // Create the autoorder request, if applicable
                    var autoOrderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder);
                    var hasAutoOrder   = autoOrderItems.Count() > 0;

                    if (hasAutoOrder)
                    {
                        var autoOrderRequest = new CreateAutoOrderRequest(AutoOrderConfiguration, Exigo.GetAutoOrderPaymentType(PropertyBag.PaymentMethod), PropertyBag.AutoOrderStartDate, PropertyBag.ShipMethodID, autoOrderItems, PropertyBag.ShippingAddress)
                        {
                            CustomerID = Identity.Current.CustomerID,
                            Frequency  = PropertyBag.AutoOrderFrequencyType
                        };
                        details.Add(autoOrderRequest);
                    }


                    // Create the payment request
                    if (PropertyBag.PaymentMethod is CreditCard)
                    {
                        var card = PropertyBag.PaymentMethod as CreditCard;
                        if (card.Type == CreditCardType.New)
                        {
                            if (hasAutoOrder)
                            {
                                card = Exigo.SaveNewCustomerCreditCard(Identity.Current.CustomerID, card);
                                ((CreateAutoOrderRequest)details.Where(c => c is CreateAutoOrderRequest).FirstOrDefault()).PaymentType = Exigo.GetAutoOrderPaymentType(card);
                            }
                            if (hasOrder)
                            {
                                if (!card.IsTestCreditCard && !Request.IsLocal)
                                {
                                    details.Add(new ChargeCreditCardTokenRequest(card));
                                }
                                else
                                {
                                    // Test Credit Card, so no need to charge card
                                    ((CreateOrderRequest)details.Where(c => c is CreateOrderRequest).FirstOrDefault()).OrderStatus = GlobalUtilities.GetDefaultOrderStatusType();
                                }
                            }
                        }
                        else
                        {
                            if (hasOrder && !Request.IsLocal)
                            {
                                details.Add(new ChargeCreditCardTokenOnFileRequest(card));
                            }
                        }
                    }
                    if (PropertyBag.PaymentMethod is BankAccount)
                    {
                        var account = PropertyBag.PaymentMethod as BankAccount;
                        if (account.Type == ExigoService.BankAccountType.New)
                        {
                            if (hasAutoOrder)
                            {
                                account = Exigo.SaveNewCustomerBankAccount(Identity.Current.CustomerID, account);
                                ((CreateAutoOrderRequest)details.Where(c => c is CreateAutoOrderRequest).FirstOrDefault()).PaymentType = Exigo.GetAutoOrderPaymentType(account);
                            }
                            if (hasOrder)
                            {
                                details.Add(new DebitBankAccountRequest(account));
                            }
                        }
                        else
                        {
                            if (hasOrder)
                            {
                                details.Add(new DebitBankAccountOnFileRequest(account));
                            }
                        }
                    }


                    // Process the transaction
                    var transactionRequest = new TransactionalRequest();
                    transactionRequest.TransactionRequests = details.ToArray();
                    var transactionResponse = Exigo.WebService().ProcessTransaction(transactionRequest);


                    var newOrderID     = 0;
                    var newAutoOrderID = 0;
                    if (transactionResponse.Result.Status == ResultStatus.Success)
                    {
                        foreach (var response in transactionResponse.TransactionResponses)
                        {
                            if (response is CreateOrderResponse)
                            {
                                newOrderID = ((CreateOrderResponse)response).OrderID;
                            }
                            if (response is CreateAutoOrderResponse)
                            {
                                newAutoOrderID = ((CreateAutoOrderResponse)response).AutoOrderID;
                            }
                        }
                    }

                    PropertyBag.NewOrderID     = newOrderID;
                    PropertyBag.NewAutoOrderID = newAutoOrderID;
                    _propertyBag = Exigo.PropertyBags.Update(PropertyBag);

                    return(new JsonNetResult(new
                    {
                        success = true
                    }));
                }
                catch (Exception exception)
                {
                    PropertyBag.OrderException = exception.Message;
                    PropertyBag.IsSubmitting   = false;
                    _propertyBag = Exigo.PropertyBags.Update(PropertyBag);

                    return(new JsonNetResult(new
                    {
                        success = false,
                        message = exception.Message
                    }));
                }
            }
            else
            {
                if (PropertyBag.NewOrderID > 0 || PropertyBag.NewAutoOrderID > 0)
                {
                    return(new JsonNetResult(new
                    {
                        success = true
                    }));
                }
                else
                {
                    return(new JsonNetResult(new
                    {
                        success = false,
                        message = Resources.Common.OrderSubmittingMessage
                    }));
                }
            }
        }