protected OrderConfirmationViewModel <T> CreateViewModel(T currentPage, IPurchaseOrder order)
        {
            var hasOrder = order != null;

            if (!hasOrder)
            {
                return(new OrderConfirmationViewModel <T> {
                    CurrentPage = currentPage
                });
            }

            var lineItems = order.GetFirstForm().Shipments.SelectMany(x => x.LineItems);
            var totals    = _orderGroupTotalsCalculator.GetOrderGroupTotals(order);

            var viewModel = new OrderConfirmationViewModel <T>
            {
                Currency                = order.Currency,
                CurrentPage             = currentPage,
                HasOrder                = hasOrder,
                OrderId                 = order.OrderNumber,
                Created                 = order.Created,
                Items                   = lineItems,
                BillingAddress          = new AddressModel(),
                ShippingAddresses       = new List <AddressModel>(),
                ContactId               = _customerContext.CurrentContactId,
                Payments                = order.GetFirstForm().Payments,
                OrderGroupId            = order.OrderLink.OrderGroupId,
                OrderLevelDiscountTotal = order.GetOrderDiscountTotal(),
                ShippingSubTotal        = order.GetShippingSubTotal(),
                ShippingDiscountTotal   = order.GetShippingDiscountTotal(),
                ShippingTotal           = totals.ShippingTotal,
                HandlingTotal           = totals.HandlingTotal,
                TaxTotal                = totals.TaxTotal,
                CartTotal               = totals.Total
            };

            var billingAddress = order.GetFirstForm().Payments.First().BillingAddress;

            // Map the billing address using the billing id of the order form.
            _addressBookService.MapToModel(billingAddress, viewModel.BillingAddress);

            // Map the remaining addresses as shipping addresses.
            foreach (var orderAddress in order.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
            {
                var shippingAddress = new AddressModel();
                _addressBookService.MapToModel(orderAddress, shippingAddress);
                viewModel.ShippingAddresses.Add(shippingAddress);
            }

            return(viewModel);
        }
Пример #2
0
        private OrderConfirmationViewModel <OrderConfirmationMailPage> CreateViewModel(OrderConfirmationMailPage currentPage, IPurchaseOrder order)
        {
            var hasOrder = order != null;

            if (!hasOrder)
            {
                return(new OrderConfirmationViewModel <OrderConfirmationMailPage>(currentPage));
            }

            var lineItems = order.GetFirstForm().Shipments.SelectMany(x => x.LineItems);
            var totals    = _orderGroupCalculator.GetOrderGroupTotals(order);

            var viewModel = new OrderConfirmationViewModel <OrderConfirmationMailPage>(currentPage)
            {
                Currency                = order.Currency,
                CurrentContent          = currentPage,
                HasOrder                = hasOrder,
                OrderId                 = order.OrderNumber,
                Created                 = order.Created,
                Items                   = lineItems,
                BillingAddress          = new AddressModel(),
                ShippingAddresses       = new List <AddressModel>(),
                ContactId               = _customerService.CurrentContactId,
                Payments                = order.GetFirstForm().Payments.Where(c => c.TransactionType == TransactionType.Authorization.ToString() || c.TransactionType == TransactionType.Sale.ToString()),
                OrderGroupId            = order.OrderLink.OrderGroupId,
                OrderLevelDiscountTotal = order.GetOrderDiscountTotal(),
                ShippingSubTotal        = order.GetShippingSubTotal(),
                ShippingDiscountTotal   = order.GetShippingDiscountTotal(),
                ShippingTotal           = totals.ShippingTotal,
                HandlingTotal           = totals.HandlingTotal,
                TaxTotal                = totals.TaxTotal,
                CartTotal               = totals.Total,
                SubTotal                = order.GetSubTotal()
            };

            var billingAddress = order.GetFirstForm().Payments.First().BillingAddress;

            // Map the billing address using the billing id of the order form.
            _addressBookService.MapToModel(billingAddress, viewModel.BillingAddress);

            // Map the remaining addresses as shipping addresses.
            foreach (var orderAddress in order.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
            {
                var shippingAddress = new AddressModel();
                _addressBookService.MapToModel(orderAddress, shippingAddress);
                viewModel.ShippingAddresses.Add(shippingAddress);
            }

            return(viewModel);
        }
        protected OrderConfirmationViewModel <T> CreateViewModel(T currentPage, IPurchaseOrder order)
        {
            if (order == null)
            {
                return(new OrderConfirmationViewModel <T> {
                    CurrentPage = currentPage
                });
            }

            var totals = _orderGroupTotalsCalculator.GetTotals(order);

            return(new OrderConfirmationViewModel <T>
            {
                Currency = order.Currency,
                CurrentPage = currentPage,
                HasOrder = true,
                OrderId = order.OrderNumber,
                Created = order.Created,
                BillingAddress = _addressBookService.ConvertToModel(order.GetFirstForm().Payments.First().BillingAddress),
                ContactId = CustomerContext.CurrentContactId,
                Payments = order.GetFirstForm().Payments.Where(c => c.TransactionType == TransactionType.Authorization.ToString() || c.TransactionType == TransactionType.Sale.ToString()),
                OrderGroupId = order.OrderLink.OrderGroupId,
                OrderLevelDiscountTotal = order.GetOrderDiscountTotal(order.Currency),
                ShippingSubTotal = order.GetShippingSubTotal(),
                ShippingDiscountTotal = order.GetShippingDiscountTotal(),
                ShippingTotal = totals.ShippingTotal,
                HandlingTotal = totals.HandlingTotal,
                TaxTotal = totals.TaxTotal,
                CartTotal = totals.Total,
                Shipments = order.Forms.SelectMany(x => x.Shipments).Select(x => new ShipmentConfirmationViewModel
                {
                    Address = _addressBookService.ConvertToModel(x.ShippingAddress),
                    LineItems = x.LineItems,
                    ShipmentCost = x.GetShippingCost(order.Market, order.Currency),
                    DiscountPrice = x.GetShipmentDiscountPrice(order.Currency),
                    ShippingItemsTotal = x.GetShippingItemsTotal(order.Currency),
                    ShippingMethodName = x.ShippingMethodName,
                })
            });
        }
Пример #4
0
        protected OrderConfirmationViewModel <T> CreateViewModel(T currentPage, IPurchaseOrder order)
        {
            var hasOrder = order != null;

            if (!hasOrder)
            {
                return(new OrderConfirmationViewModel <T>(currentPage));
            }

            var lineItems = order.GetFirstForm().Shipments.SelectMany(x => x.LineItems);
            var totals    = _orderGroupCalculator.GetOrderGroupTotals(order);

            var viewModel = new OrderConfirmationViewModel <T>(currentPage)
            {
                Currency                = order.Currency,
                CurrentContent          = currentPage,
                HasOrder                = hasOrder,
                OrderId                 = order.OrderNumber,
                Created                 = order.Created,
                Items                   = lineItems,
                BillingAddress          = new AddressModel(),
                ShippingAddresses       = new List <AddressModel>(),
                ContactId               = PrincipalInfo.CurrentPrincipal.GetContactId(),
                Payments                = order.GetFirstForm().Payments.Where(c => c.TransactionType == TransactionType.Authorization.ToString() || c.TransactionType == TransactionType.Sale.ToString()),
                OrderGroupId            = order.OrderLink.OrderGroupId,
                OrderLevelDiscountTotal = order.GetOrderDiscountTotal(),
                ShippingSubTotal        = order.GetShippingSubTotal(),
                ShippingDiscountTotal   = order.GetShippingDiscountTotal(),
                ShippingTotal           = totals.ShippingTotal,
                HandlingTotal           = totals.HandlingTotal,
                TaxTotal                = totals.TaxTotal,
                CartTotal               = totals.Total,
                SubTotal                = order.GetSubTotal(),
                FileUrls                = new List <Dictionary <string, string> >(),
                Keys = new List <Dictionary <string, string> >()
            };

            foreach (var lineItem in lineItems)
            {
                var entry   = lineItem.GetEntryContent <EntryContentBase>();
                var variant = entry as GenericVariant;
                if (entry == null || variant == null || variant.VirtualProductMode == null || variant.VirtualProductMode.Equals("None"))
                {
                    continue;
                }

                if (variant.VirtualProductMode.Equals("File"))
                {
                    var url = "";// _urlResolver.GetUrl(((FileVariant)lineItem.GetEntryContentBase()).File);
                    viewModel.FileUrls.Add(new Dictionary <string, string>()
                    {
                        { lineItem.DisplayName, url }
                    });
                }
                else if (variant.VirtualProductMode.Equals("Key"))
                {
                    var key = Guid.NewGuid().ToString();
                    viewModel.Keys.Add(new Dictionary <string, string>()
                    {
                        { lineItem.DisplayName, key }
                    });
                }
                else if (variant.VirtualProductMode.Equals("ElevatedRole"))
                {
                    viewModel.ElevatedRole = variant.VirtualProductRole;
                    var currentContact = _customerService.GetCurrentContact();
                    if (currentContact != null)
                    {
                        currentContact.ElevatedRole = ElevatedRoles.Reader.ToString();
                        currentContact.SaveChanges();
                    }
                }
            }

            var billingAddress = order.GetFirstForm().Payments.First().BillingAddress;

            // Map the billing address using the billing id of the order form.
            _addressBookService.MapToModel(billingAddress, viewModel.BillingAddress);

            // Map the remaining addresses as shipping addresses.
            foreach (var orderAddress in order.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
            {
                var shippingAddress = new AddressModel();
                _addressBookService.MapToModel(orderAddress, shippingAddress);
                viewModel.ShippingAddresses.Add(shippingAddress);
            }

            return(viewModel);
        }