public async Task <Dictionary <Product, int> > GetProductsFromCart() { var products = await PetShopDatabase.GetProductsFromCart(); Dictionary <Product, int> cartProducts = new Dictionary <Product, int>(); foreach (BasketItem b in products) { Product product = await PetShopDatabase.GetProduct(b.ProductId); cartProducts.Add(product, b.Quantity); } return(cartProducts); }
public async Task <Dictionary <Product, int> > UpdateProductsCart() { var products = await PetShopDatabase.GetProductsFromCart(); Dictionary <Product, int> productsToBasket = new Dictionary <Product, int>(); foreach (BasketItem b in products) { var prod = await PetShopDatabase.GetProduct(b.ProductId); productsToBasket.Add(prod, b.Quantity); } PropertyController.BasketListProvider.BasketProducts = productsToBasket; return(productsToBasket); }
public async void FromCartToOrder() { List <BasketItem> cartItems = await PetShopDatabase.GetProductsFromCart(); List <Product> allProducts = await GetProductsQuery(); foreach (Product p in allProducts) { try { BasketItem basketItem = cartItems.Find(x => x.ProductId == p.Id); UpdateProductInDatabase(p, p.InStock - basketItem.Quantity); RemoveProductFromCart(p); } catch (NullReferenceException) { continue; } } }