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); }
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); }