public async Task <IEnumerable <OrderDetailObject> > GetOrderDetailsInfo(int orderId)
        {
            var orderDetails = (await northwindRepository.GetOrderDetails()).Where(orderDetail => orderDetail.OrderID == orderId);

            var products = await northwindRepository.GetProducts();

            await Task.Run(() =>
            {
                orderDetails.ToList().ForEach(orderDetail =>
                {
                    orderDetail.Product = products.First(product => product.ProductID == orderDetail.ProductID);
                });
            });

            var orderDetailObjects = new ObservableCollection <OrderDetailObject>
                                         (orderDetails.Select(o => new OrderDetailObject()
            {
                OrderId     = o.OrderID,
                ProductName = o.Product.ProductName,
                UnitPrice   = o.UnitPrice,
                Quantity    = o.Quantity,
                Discount    = o.Discount * 100,
                SubTotal    = (decimal)((float)o.UnitPrice * o.Quantity * (1 - o.Discount))
            }));

            return(orderDetailObjects);
        }
Exemplo n.º 2
0
 //TODO: Why do we need to convert it to List<CustomerModel> before returning
 //TODO: Is it because of deferred execution of linq queries
 public IEnumerable <IOrderDetailModel> GetOrderDetails(int orderID)
 {
     return(_repository.GetOrderDetails(orderID)
            .Select(
                orderDetailsEntity =>
                new OrderDetailModel(orderDetailsEntity))
            .ToList());
 }
        private async void FillCollections()
        {
            var orderDetails = await northwindRepository.GetOrderDetails();

            var customers = await northwindRepository.GetCustomers();

            var products = await northwindRepository.GetProducts();

            var orders = await northwindRepository.GetOrders();

            var categories = await northwindRepository.GetCategories();

            var employees = await northwindRepository.GetEmployees();

            customersList.AddRange(customers);
            productsList.AddRange(products);
            ordersList.AddRange(orders);
            orderDetailsList.AddRange(orderDetails);

            //Filling navigation propertie(Category) of Products
            await Task.Run(() =>
            {
                products.ForEach(product =>
                {
                    product.Category = categories.First(category => category.CategoryID == product.CategoryID);
                });
            });

            //Filling naviagtion properties(Customer and Employee) of Order
            await Task.Run(() =>
            {
                orders.ForEach(order =>
                {
                    order.Customer = customers.First(customer => customer.CustomerID == order.CustomerID);
                    order.Employee = employees.First(employee => employee.EmployeeID == order.EmployeeID);
                });
            });

            //Filling naviagtion properties(Order and Product) of Order details
            await Task.Run(() =>
            {
                orderDetails.ForEach(orderDetail =>
                {
                    orderDetail.Order   = orders.First(order => order.OrderID == orderDetail.OrderID);
                    orderDetail.Product = products.First(product => product.ProductID == orderDetail.ProductID);
                });
            });

            //Starting from this moment we track changes in source lists (i.e. customersList, productsList, ordersList, orderDetailsList)
            customersByCountries.Subscribe();
            purchasesByCustomers.Subscribe();
            salesByEmployees.Subscribe();
            productsByCategories.Subscribe();
            ordersByCountries.Subscribe();
            salesByCountries.Subscribe();
            salesByCategories.Subscribe();
        }