示例#1
0
        static async void AllocateStockAsync(Runtime runtime, OrderItem orderItem)
        {
            // Allocate stock
            using (var cafeContext = CafeContextFactory.Create(runtime))
            {
                orderItem.MenuItem = cafeContext.MenuItems.FirstOrDefault(
                    searchMenuItem => searchMenuItem.Id == orderItem.MenuItemId);

                switch (orderItem.MenuItem.FoodType)
                {
                case FoodType.HotBeverage:
                    AllocateHelper.StockUpForHotBeverage(
                        cafeContext, orderItem.Quantity);
                    break;

                case FoodType.Sandwich:
                    AllocateHelper.StockUpForSandwich(
                        cafeContext, orderItem.Quantity);
                    break;

                case FoodType.Salad:
                    AllocateHelper.StockUpForSalad(
                        cafeContext, orderItem.Quantity);
                    break;
                }

                await cafeContext.SaveChangesAsync();
            }
        }
示例#2
0
        static async void CreateStockAsync(Runtime runtime, MenuItem menuItem)
        {
            using (var cafeContext = CafeContextFactory.Create(runtime))
            {
                switch (menuItem.FoodType)
                {
                case FoodType.HotBeverage:
                    AllocateHelper.AddStock(cafeContext, "Coffee");
                    AllocateHelper.AddStock(cafeContext, "Sugar");
                    AllocateHelper.AddStock(cafeContext, "Milk");
                    break;

                case FoodType.Sandwich:
                    AllocateHelper.AddStock(cafeContext, "Bread");
                    AllocateHelper.AddStock(cafeContext, "Butter");
                    AllocateHelper.AddStock(cafeContext, "Cheese");
                    break;

                case FoodType.Salad:
                    AllocateHelper.AddStock(cafeContext, "Lettuce");
                    AllocateHelper.AddStock(cafeContext, "Dressing");
                    AllocateHelper.AddStock(cafeContext, "Tomato");
                    break;
                }

                await cafeContext.SaveChangesAsync();
            }
        }