static Cake() { IngredientStore.Register(typeof(Cake), new List<Ingredient> { Ingredient.Butter, Ingredient.Eggs, Ingredient.Flour, }; }
public HomePageViewModel() { Title = "Home"; Days = new ObservableCollection <Day>(); Recipes = new ObservableCollection <Recipe>(); Ingredients = new ObservableCollection <Ingredient>(); Meals = new ObservableCollection <Meal>(); LoadDaysCommand = new Command(async(TargetDay) => await ExecuteLoadDaysCommand((DateTime)TargetDay)); LoadDaysCommand.Execute(DateTime.Now); foreach (var day in DayStore.GetItemsAsync().Result) { Days.Add(day); } foreach (var recipe in RecipeStore.GetItemsAsync().Result) { Recipes.Add(recipe); } foreach (var ingredient in IngredientStore.GetItemsAsync().Result) { Ingredients.Add(ingredient); } foreach (var meal in MealStore.GetItemsAsync().Result) { Meals.Add(meal); } MessagingCenter.Subscribe <NewRecipePage, Recipe>(this, "AddRecipe", async(obj, recipe) => { var newRecipe = recipe as Recipe; Recipes.Add(newRecipe); foreach (var Type in newRecipe.Types) { foreach (var group in _allGroups) { if (group.RecipeGroupType == Type) { group.Add(newRecipe); } } } UpdateListContents(); await RecipeStore.AddItemAsync(newRecipe); }); MessagingCenter.Subscribe <NewIngredientPage, Ingredient>(this, "AddIngredient", async(obj, ingredient) => { var newIngredient = ingredient as Ingredient; Ingredients.Add(newIngredient); await IngredientStore.AddItemAsync(newIngredient); }); }
static IngredientStore() { Current = new IngredientStore(); }