public async void LoadOrdersAsync() { List <Order> orders = null; try { orders = await PersistencyService.LoadOrdersAsync(); } catch (Exception e) { Debug.WriteLine(e); throw; } if (orders != null) { foreach (Order order in orders) { order.Supplier = SupplierList.Single(supplier => supplier.Id.Equals(order.SupplierId)); OrderList.Add(order); } } else { throw new ArgumentNullException("Orders list null"); } }
/// <summary> /// Load all Products, and product properties (Supplier, OrderList, ProductReturnList) /// from the DB into the app ProductList /// </summary> public async void LoadProductsAsync() { List <Product> products = null; try { products = await PersistencyService.LoadProductsAsync(); } catch (Exception e) { Debug.WriteLine(e); throw; } if (products != null) { foreach (Product p in products) { // Set the Supplier, Orders, and ProductReturns for the current Product // Product has a required supplier try { // Find the single supplier matching the supplier foreign key on the product p.Supplier = SupplierList.Single(s => s.Id.Equals(p.SupplierId)); } catch (Exception e) { Debug.WriteLine(e); throw; } // Get Orders in the OrderList with a foreign key to the current Product in the foreach List <Order> productOrderList = OrderList.Where(o => o.ProductId.Equals(p.Id)).ToList(); if (productOrderList != null && productOrderList.Count > 0) { p.FillOrderList(productOrderList); } // Get ProductReturns in the prList with a foreign key to the current Product in the foreach List <ProductReturn> prList = ProductReturnList.Where(pr => pr.ProductId.Equals(p.Id)).ToList(); if (prList != null && prList.Count > 0) { p.FillProductReturnList(prList); } // At last, add the product the productList ProductList.Add(p); } } else { throw new ArgumentNullException("Products list null"); } }