public ActionResult Index() { var model = new BackofficeSubscriptionsViewModel(); // Get the customer's subscriptions model.Subscriptions = Exigo.GetCustomerSubscriptions(CurrentCustomerID).ToList(); // If we have any expired subscriptions, we need to calculate how much they are going to cost to catch them up today if (model.Subscriptions.Where(c => c.SubscriptionID == Subscriptions.BackofficeFeatures).FirstOrDefault() == null || model.Subscriptions.Where(c => c.SubscriptionID == Subscriptions.BackofficeFeatures).Any(s => s.IsExpired)) { var customer = Exigo.GetCustomer(Identity.Current.CustomerID); if (customer.CreatedDate >= DateTimeExtensions.ToCST(DateTime.Now.AddMinutes(-30)) && customer.CustomerTypeID == CustomerTypes.Associate) { var cookie = new HttpCookie(GlobalSettings.Backoffices.MonthlySubscriptionCookieName); cookie.Value = "true"; cookie.Expires = DateTime.Now.AddMinutes(15); HttpContext.Response.Cookies.Add(cookie); return(RedirectToAction("Index", "Dashboard")); } // Set up our request to get the order totals on the subscriptions that are required var request = new OrderCalculationRequest(); // We pull the customer's addresses first, if there are none we calculate with the corp address var customerAddresses = Exigo.GetCustomerAddresses(CurrentCustomerID); var address = (customerAddresses.Count() > 0 && customerAddresses.Where(c => c.IsComplete == true).Count() > 0) ? customerAddresses.Where(c => c.IsComplete == true).FirstOrDefault() : GlobalSettings.Company.Address; // Find which subscriptions are expired and add the appropriate items to those where needed var itemsToCalculate = new List <ShoppingCartItem>(); itemsToCalculate.Add(new ShoppingCartItem { ItemCode = GlobalSettings.Backoffices.MonthlySubscriptionItemCode, Quantity = 1 }); model.PaymentMethods = Exigo.GetCustomerPaymentMethods(new GetCustomerPaymentMethodsRequest { CustomerID = CurrentCustomerID, ExcludeIncompleteMethods = true, ExcludeInvalidMethods = true }); request.Configuration = OrderConfiguration; request.Address = address; request.Items = itemsToCalculate; request.ShipMethodID = OrderConfiguration.DefaultShipMethodID; //82774 Ivan S. 11/24/2016 //The Commissions page was displaying an OOPS error when clicking on it, because //we were not passing in the CustomerID, and it was generating a null exception //Therefore I added this line of code: request.CustomerID = Identity.Current.CustomerID; model.OrderCalcResponse = Exigo.CalculateOrder(request); } return(View(model)); }
// Order Calculation public OrderCalculationResult CalculateOrder(OrderCalculationRequest request) { var result = new OrderCalculationResult(); if (request.Items.Count() == 0) { return(result); } if (request.Address == null) { request.Address = GlobalSettings.Company.DefaultCalculationAddress; } if (request.ShipMethodID == 0) { request.ShipMethodID = request.Configuration.DefaultShipMethodID; } var apirequest = new CalculateOrderRequest(); apirequest.WarehouseID = request.Configuration.WarehouseID; apirequest.CurrencyCode = request.Configuration.CurrencyCode; apirequest.PriceType = request.Configuration.PriceTypeID; apirequest.ShipMethodID = request.ShipMethodID; apirequest.ReturnShipMethods = request.ReturnShipMethods; apirequest.City = request.Address.City; apirequest.State = request.Address.State; apirequest.Zip = request.Address.Zip; apirequest.Country = request.Address.Country; apirequest.Details = request.Items.Select(c => new OrderDetailRequest(c)).ToArray(); var apiresponse = Exigo.WebService().CalculateOrder(apirequest); result.Subtotal = apiresponse.SubTotal; result.Shipping = apiresponse.ShippingTotal; result.Tax = apiresponse.TaxTotal; result.Discount = apiresponse.DiscountTotal; result.Total = apiresponse.Total; // Assemble the ship methods var shipMethods = new List <IShipMethod>(); if (apiresponse.ShipMethods != null) { foreach (var shipMethod in apiresponse.ShipMethods.Where(s => request.Configuration.AvailableShipMethods.Contains(s.ShipMethodID))) { shipMethods.Add(GlobalUtilities.TranslateShipMethods((ShipMethod)shipMethod)); } // Ensure that at least one ship method is selected var shipMethodID = (request.ShipMethodID != 0) ? request.ShipMethodID : request.Configuration.DefaultShipMethodID; if (shipMethods.Any(c => c.ShipMethodID == shipMethodID)) { shipMethods.First(c => c.ShipMethodID == shipMethodID).Selected = true; } else { shipMethods.First().Selected = true; } } result.ShipMethods = shipMethods.AsEnumerable(); var test = ""; return(result); }