Exemplo n.º 1
0
        public async Task PopulatePurchases()
        {
            ProductList = new List <Product>();
            PurchasesList.Clear();

            ProductList = new List <Product>(await _productRepository.GetAllProductData());


            foreach (Product item in ProductList)
            {
                switch (item.Category)
                {
                case "Drinks":
                {
                    Purchase temp = new Purchase()
                    {
                        ProductId       = item.Id,
                        ProductName     = item.Name,
                        ProductPrice    = item.Price,
                        ProductQuantity = item.Quantity,
                        ProductCategory = item.Category,
                        IsCompleted     = false
                    };

                    DrinksPurchasesList.Add(temp);
                    PurchasesList.Add(temp);
                    break;
                }

                case "Food":
                {
                    Purchase temp2 = new Purchase()
                    {
                        ProductId       = item.Id,
                        ProductName     = item.Name,
                        ProductPrice    = item.Price,
                        ProductQuantity = item.Quantity,
                        ProductCategory = item.Category,
                        IsCompleted     = false
                    };

                    FoodPurchasesList.Add(temp2);
                    PurchasesList.Add(temp2);
                    break;
                }

                case "Snacks":
                    Purchase temp3 = new Purchase()
                    {
                        ProductId       = item.Id,
                        ProductName     = item.Name,
                        ProductPrice    = item.Price,
                        ProductQuantity = item.Quantity,
                        ProductCategory = item.Category,
                        IsCompleted     = false
                    };

                    SnacksPurchasesList.Add(temp3);
                    PurchasesList.Add(temp3);
                    break;

                default:
                    break;
                }
            }
        }
Exemplo n.º 2
0
        private void changePurchasesContextAndSave()
        {
            foreach (Purchase item in PurchasesList)
            {
                switch (item.ProductCategory)
                {
                case "Drinks":
                {
                    if (item.UnitsOfProduct > 0)
                    {
                        foreach (var drinkItem in DrinksPurchasesList)
                        {
                            if (drinkItem.ProductId == item.ProductId)
                            {
                                int indx = DrinksPurchasesList.IndexOf(drinkItem);
                                DrinksPurchasesList.RemoveAt(indx);
                                DrinksPurchasesList.Add(item);
                                break;
                            }
                        }
                    }
                    break;
                }

                case "Food":
                {
                    if (item.UnitsOfProduct > 0)
                    {
                        foreach (var foodItem in FoodPurchasesList)
                        {
                            if (foodItem.ProductId == item.ProductId)
                            {
                                int indx = FoodPurchasesList.IndexOf(foodItem);
                                FoodPurchasesList.RemoveAt(indx);
                                FoodPurchasesList.Add(item);
                                break;
                            }
                        }
                    }
                    break;
                }

                case "Snacks":
                {
                    if (item.UnitsOfProduct > 0)
                    {
                        foreach (var snacksItem in SnacksPurchasesList)
                        {
                            if (snacksItem.ProductId == item.ProductId)
                            {
                                int indx = SnacksPurchasesList.IndexOf(snacksItem);
                                SnacksPurchasesList.RemoveAt(indx);
                                SnacksPurchasesList.Add(item);
                                break;
                            }
                        }
                    }
                    break;
                }

                default:
                    break;
                }
            }

            switch (Category)
            {
            case "Drinks":
                PurchasesList.Clear();
                foreach (var item in DrinksPurchasesList)
                {
                    PurchasesList.Add(item);
                }
                break;

            case "Food":
                PurchasesList.Clear();
                foreach (var item in FoodPurchasesList)
                {
                    PurchasesList.Add(item);
                }
                break;

            case "Snacks":
                PurchasesList.Clear();
                foreach (var item in SnacksPurchasesList)
                {
                    PurchasesList.Add(item);
                }
                break;

            default:
                break;
            }
        }