/// <summary> /// Method to update the list of available ingredients /// </summary> /// <returns></returns> public async Task UpdateIngredientLists() { // Getting all ingredients from the database... AllAvailableIngredientsList = await rep.GetAllCondiments(); // ...and casting it to queryable list var IngredientsToChooseFrom = AllAvailableIngredientsList.Cast <BackendHandler.Condiment>().ToList(); // Goes through the already set ingredients CondimentsOnPizza.Cast <BackendHandler.Condiment>().ToList().ForEach(x => { // and removing them from the list of available condiments for (int i = 0; i < IngredientsToChooseFrom.Count; i++) { if (x.CondimentID == IngredientsToChooseFrom[i].CondimentID) { IngredientsToChooseFrom.Remove(IngredientsToChooseFrom[i]); } } }); // Updates the list of available ingredients AllAvailableIngredientsList = IngredientsToChooseFrom; BasePizza.PizzaIngredients = CondimentsOnPizza.Cast <BackendHandler.Condiment>().ToList(); }
/// <summary> /// Command to add the selected ingredient in a list to the pizza /// </summary> public async Task AddIngredientCommand() { // Adds the selected condiment to the pizza CondimentsOnPizza.Add(CondimentToAdd); // And updates the UI await UpdateIngredientLists(); }
/// <summary> /// Command to remove a selected ingredient in a list from the pizza /// </summary> public async Task RemoveIngredientCommand() { // Removes the selected condiment CondimentsOnPizza.Remove(CondimentToRemove); // And adds it back to the list of available condiments AllAvailableIngredientsList.Cast <BackendHandler.Condiment>().ToList().Add(CondimentToRemove); // Updates the lists await UpdateIngredientLists(); }
/// <summary> /// Method to load previously added ingredients to the chosen pizza /// </summary> /// <returns></returns> public async Task LoadIngredientsToExistingPizza() { if (BasePizza.PizzaID != 0) { // getting all ingredients of the sent in pizza var ingredients = await rep.GetIngredientsFromSpecificPizza(BasePizza.PizzaID); // Ordering the ingredients var OrderedIngredients = ingredients.OrderBy(x => x.CondimentID); // and updates the pizza with it BasePizza.PizzaIngredients = OrderedIngredients.ToList(); // Putting all the ingredients that a pizza has to the temporary condiment list BasePizza.PizzaIngredients.ForEach(x => { CondimentsOnPizza.Add(x); }); } }