Exemplo n.º 1
0
        public ActionResult Index(OrderHistoryPage currentPage, int?page, int?size)
        {
            var pageNum        = page ?? 1;
            var pageSize       = size ?? 10;
            var orders         = _orderRepository.Load <IPurchaseOrder>(PrincipalInfo.CurrentPrincipal.GetContactId(), _cartService.DefaultCartName);
            var purchaseOrders = orders
                                 .OrderByDescending(x => x.Created)
                                 .Skip((pageNum - 1) * pageSize)
                                 .Take(pageSize)
                                 .ToList();

            var viewModel = new OrderHistoryViewModel(currentPage)
            {
                CurrentContent = currentPage,
                Orders         = new List <OrderViewModel>()
            };

            foreach (var purchaseOrder in purchaseOrders)
            {
                // Assume there is only one form per purchase.
                var form           = purchaseOrder.GetFirstForm();
                var billingAddress = new AddressModel();
                var payment        = form.Payments.FirstOrDefault();
                if (payment != null)
                {
                    billingAddress = _addressBookService.ConvertToModel(payment.BillingAddress);
                }
                var orderViewModel = new OrderViewModel
                {
                    PurchaseOrder = purchaseOrder,
                    Items         = form.GetAllLineItems().Select(lineItem => new OrderHistoryItemViewModel
                    {
                        LineItem = lineItem,
                    }).GroupBy(x => x.LineItem.Code).Select(group => group.First()),
                    BillingAddress    = billingAddress,
                    ShippingAddresses = new List <AddressModel>()
                };

                foreach (var orderAddress in purchaseOrder.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
                {
                    var shippingAddress = _addressBookService.ConvertToModel(orderAddress);
                    orderViewModel.ShippingAddresses.Add(shippingAddress);
                }

                viewModel.Orders.Add(orderViewModel);
            }
            viewModel.OrderDetailsPageUrl =
                UrlResolver.Current.GetUrl(_contentLoader.Get <CommerceHomePage>(ContentReference.StartPage).OrderDetailsPage);

            viewModel.PagingInfo.PageNumber  = pageNum;
            viewModel.PagingInfo.TotalRecord = orders.Count();
            viewModel.PagingInfo.PageSize    = pageSize;
            viewModel.OrderHistoryUrl        = currentPage.StaticLinkURL;
            return(View(viewModel));
        }
Exemplo n.º 2
0
        public ActionResult Index(OrderHistoryPage currentPage, OrderFilter filter, int?page, int?size, int?isPaging)
        {
            if (isPaging.HasValue)
            {
                filter = GetFilter();
            }
            else
            {
                SetCookieFilter(filter);
            }
            var pageNum        = page ?? 1;
            var pageSize       = size ?? 10;
            var orders         = _orderRepository.Load <IPurchaseOrder>(PrincipalInfo.CurrentPrincipal.GetContactId(), _cartService.DefaultCartName);
            var purchaseOrders = FilterOrders(orders, filter)
                                 .OrderByDescending(x => x.Created)
                                 .Skip((pageNum - 1) * pageSize)
                                 .Take(pageSize)
                                 .ToList();

            var viewModel = new OrderHistoryViewModel(currentPage)
            {
                CurrentContent = currentPage,
                Orders         = new List <OrderViewModel>(),
            };

            OrderFilter.LoadDefault(filter, _paymentMethodViewModelFactory);
            LoadAvailableAddresses(filter);

            foreach (var purchaseOrder in purchaseOrders)
            {
                // Assume there is only one form per purchase.
                var form           = purchaseOrder.GetFirstForm();
                var billingAddress = new AddressModel();
                var payment        = form.Payments.FirstOrDefault();
                if (payment != null)
                {
                    billingAddress = _addressBookService.ConvertToModel(payment.BillingAddress);
                }
                var orderViewModel = new OrderViewModel
                {
                    PurchaseOrder = purchaseOrder,
                    Items         = form.GetAllLineItems().Select(lineItem => new OrderHistoryItemViewModel
                    {
                        LineItem = lineItem,
                    }).GroupBy(x => x.LineItem.Code).Select(group => group.First()),
                    BillingAddress    = billingAddress,
                    ShippingAddresses = new List <AddressModel>()
                };

                foreach (var orderAddress in purchaseOrder.Forms.SelectMany(x => x.Shipments).Select(s => s.ShippingAddress))
                {
                    var shippingAddress = _addressBookService.ConvertToModel(orderAddress);
                    orderViewModel.ShippingAddresses.Add(shippingAddress);
                }

                viewModel.Orders.Add(orderViewModel);
            }
            viewModel.OrderDetailsPageUrl =
                UrlResolver.Current.GetUrl(_settingsService.GetSiteSettings <ReferencePageSettings>()?.OrderDetailsPage ?? ContentReference.StartPage);

            viewModel.PagingInfo.PageNumber  = pageNum;
            viewModel.PagingInfo.TotalRecord = purchaseOrders.Count();
            viewModel.PagingInfo.PageSize    = pageSize;
            viewModel.OrderHistoryUrl        = Request.Url.PathAndQuery;
            viewModel.Filter = filter;
            return(View(viewModel));
        }