public GoogleAnalyticsEnableReportingDataModel GetGoogleAnalyticsViewModel(TempCart tempCart) { if (tempCart == null || !tempCart.IsCompleted) { return(new GoogleAnalyticsEnableReportingDataModel()); } var model = new GoogleAnalyticsEnableReportingDataModel(); if (tempCart.EventPackageId.HasValue) { model.EventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value); } if (!string.IsNullOrEmpty(tempCart.TestId)) { var testIdStrings = tempCart.TestId.Split(new[] { ',' }); if (testIdStrings.Any()) { long id; var testIds = testIdStrings.Where(p => long.TryParse(p, out id)).Select(p => Convert.ToInt64(p)).ToArray(); if (testIds.Count() > 0) { model.EventTests = _eventTestRepository.GetbyIds(testIds); } } } if (!string.IsNullOrEmpty(tempCart.ProductId)) { var productIdStrings = tempCart.ProductId.Split(new[] { ',' }); if (productIdStrings.Any()) { long id; var productIds = productIdStrings.Where(p => long.TryParse(p, out id)).Select(p => Convert.ToInt64(p)).ToArray(); if (productIds.Count() > 0) { model.Products = _productRepository.GetByIds(productIds); } } } if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0) { model.Shipping = _shippingOptionRepository.GetById(tempCart.ShippingId.Value).Price; } Order order = _orderRepository.GetOrder(tempCart.CustomerId.Value, tempCart.EventId.Value); model.TotalPrice = order.DiscountedTotal; model.CustomerId = tempCart.CustomerId.Value; var customer = _customerRepository.GetCustomer(tempCart.CustomerId.Value); model.Address = _addressService.GetAddress(customer.Address.Id); return(model); }
public ActionResult DeliveryDetails(DeliveryDetailsViewModel model) { // Gets the current user's shopping cart ShoppingCart cart = shoppingService.GetCurrentShoppingCart(); // Gets all enabled shipping options for the shipping option selector SelectList shippingOptions = new SelectList(shippingOptionRepository.GetAllEnabled(), "ShippingOptionID", "ShippingOptionDisplayName"); // If the ModelState is not valid, assembles the country list and the shipping option list and displays the step again if (!ModelState.IsValid) { SelectList countries = new SelectList(CountryInfoProvider.GetCountries(), "CountryID", "CountryDisplayName"); model.BillingAddress.Countries = countries; model.ShippingOption.ShippingOptions = new ShippingOptionModel(cart.ShippingOption, shippingOptions).ShippingOptions; return(View(model)); } // Gets the shopping cart's customer and applies the customer details from the checkout process step if (cart.Customer == null) { cart.Customer = new Customer(); } model.Customer.ApplyToCustomer(cart.Customer); // Gets the shopping cart's billing address and applies the billing address from the checkout process step cart.BillingAddress = addressRepository.GetById(model.BillingAddress.AddressID) ?? new CustomerAddress(); model.BillingAddress.ApplyTo(cart.BillingAddress); // Sets the address personal name cart.BillingAddress.PersonalName = $"{cart.Customer.FirstName} {cart.Customer.LastName}"; // Sets the selected shipping option cart.ShippingOption = shippingOptionRepository.GetById(model.ShippingOption.ShippingOptionID); // Evaluates the shopping cart cart.Evaluate(); // Saves the shopping cart cart.Save(); // Redirects to the next step of the checkout process return(RedirectToAction("PreviewAndPay")); }
/// <summary> /// Gets shipping option info. /// </summary> /// <param name="shippingOptionId">ID of shipping option which should be returned.</param> public ShippingOptionInfo GetShippingOption(int shippingOptionId) { return(mShippingOptionRepository.GetById(shippingOptionId)); }
public SourceCodeApplyEditModel GetSourceCodeApplied(TempCart tempCart, SourceCodeApplyEditModel sourceCodeModel = null) { var model = new SourceCodeApplyEditModel { SignUpMode = (int)SignUpMode.Online, SourceCodeHelpDescription = _toolTipRepository.GetToolTipContentByTag(ToolTipType.SourceCodeHelp) }; if (tempCart == null) { return(model); } if (tempCart.EventId.HasValue) { model.EventId = tempCart.EventId.Value; } if (tempCart.CustomerId.HasValue) { model.CustomerId = tempCart.CustomerId.Value; } decimal orderTotal = 0; if (tempCart.EventPackageId.HasValue) { var eventPackage = _eventPackageRepository.GetById(tempCart.EventPackageId.Value); model.Package = new OrderedPair <long, decimal>(eventPackage.PackageId, eventPackage.Price); orderTotal += model.Package.SecondValue; } if (!string.IsNullOrEmpty(tempCart.TestId)) { var eventTestIds = tempCart.TestId.Split(new[] { ',' }).Select(t => Convert.ToInt64(t.Trim())); var eventTests = _eventTestRepository.GetbyIds(eventTestIds); model.SelectedTests = eventTests.Select(et => new OrderedPair <long, decimal>(et.TestId, tempCart.EventPackageId.HasValue ? et.WithPackagePrice : et.Price)).ToArray(); orderTotal += model.SelectedTests.Sum(s => s.SecondValue); } if (tempCart.ShippingId.HasValue && tempCart.ShippingId.Value > 0) { var shippingOption = _shippingOptionRepository.GetById(tempCart.ShippingId.Value); model.ShippingAmount = shippingOption.Price; orderTotal += model.ShippingAmount; } if (!string.IsNullOrEmpty(tempCart.ProductId)) { var productids = tempCart.ProductId.Split(new[] { ',' }).Select(t => Convert.ToInt64(t.Trim())); var products = _productRepository.GetByIds(productids); model.ProductAmount = products.Sum(p => p.Price); orderTotal += model.ProductAmount; } model.OrderTotal = orderTotal; if (sourceCodeModel != null && sourceCodeModel.SourceCodeId > 0) { var sourceCode = _sourceCodeRepository.GetSourceCodeById(sourceCodeModel.SourceCodeId); model.SourceCode = sourceCode.CouponCode; model = ApplySourceCode(model); } else if (tempCart.SourceCodeId.HasValue && tempCart.SourceCodeId > 0) { var sourceCode = _sourceCodeRepository.GetSourceCodeById(tempCart.SourceCodeId.Value); model.SourceCode = sourceCode.CouponCode; model = ApplySourceCode(model); } return(model); }