Пример #1
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 <IOrderModel> GetOrders(string customerID)
 {
     return(_repository.GetOrders(customerID)
            .Select(
                orderEntity => new OrderModel(orderEntity))
            .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();
        }
Пример #3
0
        public async void OnNavigatedTo(NavigationContext navigationContext)
        {
            try
            {
                cachedCollection = await northwindRepository.GetOrders();

                Orders = cachedCollection;
            }
            catch (Exception e)
            {
                if (e is EntityCommandCompilationException || e is DbException)
                {
                    MessageBus.Current.SendMessage(e);
                }
            }
        }
        public async Task <IEnumerable <OrderObject> > GetOrdersInfo(int orderId)
        {
            var order = (await northwindRepository.GetOrders()).First(a => a.OrderID == orderId);

            var customer = (await northwindRepository.GetCustomers()).First(a => a.CustomerID == order.CustomerID);

            var employee = (await northwindRepository.GetEmployees()).First(a => a.EmployeeID == order.EmployeeID);

            order.Customer = customer;
            order.Employee = employee;

            var orderObject = new ObservableCollection <OrderObject>();

            orderObject.Add(new OrderObject()
            {
                OrderId      = order.OrderID,
                OrderDate    = order.OrderDate.Value,
                EmployeeName = order.Employee.FirstName + " " + order.Employee.LastName,
                CustomerName = order.Customer.CompanyName
            });

            return(orderObject);
        }