public JsonNetResult CalculateAutoOrder(ManageAutoOrderViewModel model) { try { var calculateOrderResponse = ExigoDAL.CalculateOrder(new OrderCalculationRequest { Address = model.AutoOrder.ShippingAddress, ShipMethodID = model.AutoOrder.ShipMethodID, ReturnShipMethods = true, Configuration = Identity.Customer.Market.Configuration.AutoOrders, CustomerID = Identity.Customer.CustomerID, Items = model.AutoOrder.Details.Select(i => new ShoppingCartItem { ItemCode = i.ItemCode, Quantity = i.Quantity }) }); return(new JsonNetResult(new { success = true, shipmethods = calculateOrderResponse.ShipMethods.ToList() })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, message = ex.Message })); } }
public JsonNetResult UpdateItemSummary(bool?hideControls) { try { var model = new EnrollmentSummaryViewModel(); var order = new OrderCalculationResponse(); var hasShippingAddress = (PropertyBag.ShippingAddress != null && PropertyBag.ShippingAddress.IsComplete); var orderItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order || c.Type == ShoppingCartItemType.EnrollmentPack).ToList(); if (hasShippingAddress) { model.IsCalculated = true; order = ExigoDAL.CalculateOrder(new OrderCalculationRequest { Configuration = OrderConfiguration, Items = orderItems, Address = PropertyBag.ShippingAddress, ShipMethodID = PropertyBag.ShipMethodID, ReturnShipMethods = true }); model.Total = order.Total; model.Shipping = order.Shipping; model.Tax = order.Tax; } model.OrderItems = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order), OrderConfiguration, CurrentLanguage.LanguageID); model.AutoOrderItems = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder), AutoOrderConfiguration, CurrentLanguage.LanguageID); model.OrderEnrollmentPacks = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.EnrollmentPack), OrderPacksConfiguration, CurrentLanguage.LanguageID); model.AutoOrderEnrollmentPacks = ExigoDAL.GetItems(ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.EnrollmentAutoOrderPack), AutoOrderConfiguration, CurrentLanguage.LanguageID); var autoOrderSubtotal = model.AutoOrderItems.Sum(c => c.Price * c.Quantity); var autoOrderPackSubtotal = model.AutoOrderEnrollmentPacks.Sum(c => c.Price * c.Quantity); var orderSubtotal = model.OrderItems.Sum(c => c.Price * c.Quantity); var orderPackSubtotal = model.OrderEnrollmentPacks.Sum(c => c.Price * c.Quantity); model.OrderSubtotal = (hasShippingAddress) ? order.Subtotal : (orderSubtotal + orderPackSubtotal); model.AutoOrderSubtotal = autoOrderPackSubtotal + autoOrderSubtotal; return(new JsonNetResult(new { success = true, orderitems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order), autoorderitems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.AutoOrder), html = this.RenderPartialViewToString("_EnrollmentSummary", model, new ViewDataDictionary { { "HideControls", hideControls } }) })); } catch (Exception ex) { return(new JsonNetResult(new { success = false, error = ex.Message })); } }
public ActionResult Review() { var model = EnrollmentViewModelFactory.Create <EnrollmentReviewViewModel>(PropertyBag); // Get the cart items var cartItems = ShoppingCart.Items.Where(c => c.Type == ShoppingCartItemType.Order || c.Type == ShoppingCartItemType.EnrollmentPack).ToList(); model.Items = ExigoDAL.GetItems(ShoppingCart.Items, OrderConfiguration, CurrentLanguage.LanguageID).ToList(); var calculationResult = ExigoDAL.CalculateOrder(new OrderCalculationRequest { Configuration = OrderConfiguration, Items = cartItems, Address = PropertyBag.ShippingAddress, ShipMethodID = PropertyBag.ShipMethodID, ReturnShipMethods = true }); model.Totals = calculationResult; model.ShipMethods = calculationResult.ShipMethods; // Set the default ship method var shipMethodID = 0; if (PropertyBag.ShipMethodID != 0) { shipMethodID = PropertyBag.ShipMethodID; } else { shipMethodID = OrderConfiguration.DefaultShipMethodID; PropertyBag.ShipMethodID = OrderConfiguration.DefaultShipMethodID; ExigoDAL.PropertyBags.Update(PropertyBag); } if (model.ShipMethods != null) { if (model.ShipMethods.Any(c => c.ShipMethodID == shipMethodID)) { model.ShipMethods.First(c => c.ShipMethodID == shipMethodID).Selected = true; } else { // If we don't have the ship method we're supposed to select, // check the first one, save the selection and recalculate model.ShipMethods.First().Selected = true; PropertyBag.ShipMethodID = model.ShipMethods.First().ShipMethodID; ExigoDAL.PropertyBags.Update(PropertyBag); var newCalculationResult = ExigoDAL.CalculateOrder(new OrderCalculationRequest { Configuration = OrderConfiguration, Items = cartItems, Address = PropertyBag.ShippingAddress, ShipMethodID = PropertyBag.ShipMethodID, ReturnShipMethods = false }); model.Totals = newCalculationResult; } } else { } return(View(model)); }
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)); }