コード例 #1
0
ファイル: ShoppingViewModel.cs プロジェクト: mikeek/FIT
 public void UpdateRequiredIngredients()
 {
     RequiredAmounts.Clear();
     foreach (IngredientAmount amount in _totalRequiredAmounts)
     {
         if (amount.Amount > amount.Ingredient.InStoreAmount)
         {
             IngredientAmount updatedAmount = GetAmount(RequiredAmounts, amount.Ingredient);
             updatedAmount.Amount = amount.Amount - amount.Ingredient.InStoreAmount;
         }
         else
         {
             IngredientAmount deleteAmount = RequiredAmounts.FirstOrDefault(
                 i => i.Ingredient.Id == amount.Ingredient.Id);
             if (deleteAmount != null)
             {
                 RequiredAmounts.Remove(deleteAmount);
             }
         }
     }
 }
コード例 #2
0
ファイル: ShoppingViewModel.cs プロジェクト: mikeek/FIT
        public void GetIngredientsRequests()
        {
            // Remove current list of required ingredients
            _totalRequiredAmounts.Clear();
            RequiredAmounts.Clear();

            // Get all meals in selected time range
            DateTime endDate      = _startDate.AddDays(ShowDays);
            var      plannedMeals = new ObservableCollection <Meal>(
                Items.Where(it => it.MealTime.Day.Date >= _startDate.Date && it.MealTime.Day.Date <= endDate.Date));

            // For each meal update list of required ingredients
            foreach (var meal in plannedMeals)
            {
                foreach (var mealIngredient in meal.Recipe.Ingredients)
                {
                    var requiredIngr = GetAmount(_totalRequiredAmounts, mealIngredient.Ingredient);
                    requiredIngr.Amount += meal.Count * mealIngredient.Amount;
                }
            }

            UpdateRequiredIngredients();
        }