コード例 #1
0
 public RecipeIngredientViewModel(RecipeIngredientViewModel other, int portion)
 {
     this._ingredient = other._ingredient;
     this._relation   = new RecipeIngredientRelation {
         IngredientId = other.IngredientId, Quantity = other.Quantity * portion, Unit = other.Unit
     };
 }
コード例 #2
0
 private ObservableCollection <RecipeIngredientViewModel> loadIngredients()
 {
     _ingredients = new ObservableCollection <RecipeIngredientViewModel>();
     foreach (var menuItem in this)
     {
         int portion = menuItem.Portion;
         foreach (var ingredient in menuItem.Recipe.Ingredients)
         {
             var previous = _ingredients.FirstOrDefault(x => x.IngredientId.Equals(ingredient.IngredientId));
             if (previous != null)
             {
                 previous.Quantity += portion * ingredient.Quantity;
             }
             else
             {
                 RecipeIngredientViewModel newIngredient = new RecipeIngredientViewModel(ingredient, portion);
                 _ingredients.Add(newIngredient);
             }
         }
     }
     return(_ingredients);
 }