public IEnumerable<OrderInfo> GetAll(int start, int pageSize) { var orders = GetAll(); var customers = new CustomerRepository().GetAll().ToDictionary(c => c.CustomerID); var orderItems = new OrderItemRepository().GetAll().ToArray(); var results = orders.Skip(start) .Take(pageSize) .Select(o => new { OrderID = o.OrderID, OrderDate = o.OrderDate, CustomerName = customers[o.CustomerID].Name, CustomerID = o.CustomerID, OrderItems = orderItems.Where(i => i.OrderID == o.OrderID) }) .Select(o => new OrderInfo() { OrderID = o.OrderID, OrderDate = o.OrderDate, CustomerName = o.CustomerName, CustomerID = o.CustomerID, Total = o.OrderItems.Sum(i => i.Amount), Status = BuildStatusName(o.OrderItems), HasShippedItems = o.OrderItems.Any(i => i.OrderStatus() is ShippedState) }); return results.ToArray(); }
void MainWindow_Loaded(object sender, RoutedEventArgs e) { var productsDataProxy = new ProductRepository(); var inventoryDataProxy = new InventoryItemRepository(); var customerDataProxy = new CustomerRepository(); var orderItemDataProxy = new OrderItemRepository(); var orderRepository = new OrderRepository(customerDataProxy, orderItemDataProxy); _inventoryService = new InventoryItemService(inventoryDataProxy); _orderItemsService = new OrderItemService(orderItemDataProxy, productsDataProxy, inventoryDataProxy, new DTCTransactionContext()); _ordersService = new OrderService(orderRepository, _orderItemsService, new DTCTransactionContext()); _customersService = new CustomerService(customerDataProxy, _ordersService); _productsService = new ProductService(productsDataProxy, _ordersService, _inventoryService, new DTCTransactionContext()); _categoriesService = new CategoryService(new CategoryRepository(), _productsService); this.DataContext = new MainWindowVM(_eventAggregator, _customersService, _productsService, _categoriesService, _ordersService, _inventoryService); }