public ActionResult EnrollmentComplete(string token)
        {
            var model        = new EnrollmentCompleteViewModel();
            var args         = Security.Decrypt(token);
            var hasOrder     = args["OrderID"] != null;
            var hasAutoOrder = args["AutoOrderID"] != null;

            model.CustomerID = Convert.ToInt32(args["CustomerID"]);
            if (hasOrder)
            {
                model.OrderID = Convert.ToInt32(args["OrderID"]);
                model.Order   = ExigoDAL.GetCustomerOrders(new GetCustomerOrdersRequest
                {
                    CustomerID          = model.CustomerID,
                    OrderID             = model.OrderID,
                    IncludeOrderDetails = true,
                    IncludePayments     = true
                }).FirstOrDefault();
            }
            if (hasAutoOrder)
            {
                model.AutoOrderID = Convert.ToInt32(args["AutoOrderID"]);
                try
                {
                    model.AutoOrder = ExigoDAL.GetCustomerAutoOrders(Identity.Customer.CustomerID, model.AutoOrderID).FirstOrDefault();
                }
                catch { }
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult AutoOrderList()
        {
            var viewModel = new AutoOrderListViewModel();

            viewModel.AutoOrders = ExigoDAL.GetCustomerAutoOrders(Identity.Customer.CustomerID, includePaymentMethods: false);

            if (!viewModel.AutoOrders.Any())
            {
                return(RedirectToAction("NoActiveAutoOrdersFound"));
            }

            return(View(viewModel));
        }
Exemplo n.º 3
0
        public ActionResult ManageAutoOrder(int id)
        {
            var viewModel  = new ManageAutoOrderViewModel();
            var customerID = Identity.Customer.CustomerID;
            var customer   = Customers.GetCustomer(customerID);
            var autoOrder  = ExigoDAL.GetCustomerAutoOrders(customerID, id).FirstOrDefault();
            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 isExistingAutoOrder = id != 0;

            if (isExistingAutoOrder)
            {
                viewModel.AutoOrder           = autoOrder;
                viewModel.AutoOrder.StartDate = ExigoDAL.GetNextAvailableAutoOrderStartDate(viewModel.AutoOrder.NextRunDate ?? DateTime.Now);

                // Fill in any blanks in the recipient
                viewModel.AutoOrder.ShippingAddress.FirstName  = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.FirstName, customer.FirstName);
                viewModel.AutoOrder.ShippingAddress.MiddleName = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.MiddleName, customer.MiddleName);
                viewModel.AutoOrder.ShippingAddress.LastName   = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.LastName, customer.LastName);
                viewModel.AutoOrder.ShippingAddress.Company    = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Company, customer.Company);
                viewModel.AutoOrder.ShippingAddress.Email      = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Email, customer.Email);
                viewModel.AutoOrder.ShippingAddress.Phone      = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Phone, customer.PrimaryPhone, customer.SecondaryPhone, customer.MobilePhone);
            }
            else
            {
                var customerShippingAddress = customer.ShippingAddresses.Where(a => a.IsComplete && a.Country == Identity.Customer.Country).FirstOrDefault();

                viewModel.AutoOrder = new AutoOrder()
                {
                    FrequencyTypeID        = FrequencyTypes.Monthly,
                    CurrencyCode           = configuration.CurrencyCode,
                    AutoOrderPaymentTypeID = AutoOrderPaymentTypes.PrimaryCreditCardOnFile,
                    StartDate       = ExigoDAL.GetNextAvailableAutoOrderStartDate(DateTime.Now),
                    ShippingAddress = (customerShippingAddress != null) ? customerShippingAddress : new ShippingAddress()
                    {
                        Country = Identity.Customer.Country
                    },
                    ShipMethodID = configuration.DefaultShipMethodID
                };

                viewModel.AutoOrder.ShippingAddress.Phone = GlobalUtilities.Coalesce(viewModel.AutoOrder.ShippingAddress.Phone, customer.PrimaryPhone, customer.SecondaryPhone, customer.MobilePhone);
                viewModel.UsePointAccount = false;
            }

            // Get Available Ship Methods, if we are managing an existing auto order
            if (isExistingAutoOrder)
            {
                var calculateOrderResponse = ExigoDAL.CalculateOrder(new OrderCalculationRequest
                {
                    Address           = viewModel.AutoOrder.ShippingAddress,
                    ShipMethodID      = viewModel.AutoOrder.ShipMethodID,
                    ReturnShipMethods = true,
                    Configuration     = Identity.Customer.Market.Configuration.AutoOrders,
                    CustomerID        = Identity.Customer.CustomerID,
                    Items             = viewModel.AutoOrder.Details.Select(i => new ShoppingCartItem {
                        ItemCode = i.ItemCode, Quantity = i.Quantity
                    })
                });
                viewModel.AvailableShipMethods = calculateOrderResponse.ShipMethods.ToList();
            }
            else
            {
                // Give the View a default ship method for display only
                viewModel.AvailableShipMethods = new List <ShipMethod> {
                    new ShipMethod {
                        Price = 0, Selected = true, ShipMethodDescription = "---", ShipMethodID = 0
                    }
                };
            }

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

            return(View(viewModel));
        }