public ActionResult Edit(int id, Pizza pizza, int pate, List <int> ingredients) { try { Pate patePizza = Pates.FirstOrDefault(p => p.Id == pate); List <Ingredient> ingredientsPizza = new List <Ingredient>(); foreach (var ingr in ingredients) { ingredientsPizza.Add(Ingredients.FirstOrDefault(i => i.Id == ingr)); } var maPizza = Pizzas.FirstOrDefault(p => p.Id == id); maPizza.Nom = pizza.Nom; maPizza.Pate = patePizza; maPizza.Ingredients = ingredientsPizza; Pizzas.Remove(Pizzas.FirstOrDefault(p => p.Id == maPizza.Id)); Pizzas.Add(maPizza); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Create(Pizza pizza, int pate, List <int> ingredients) { try { if (pizza != null) { Pate patePizza = Pates.FirstOrDefault(p => p.Id == pate); List <Ingredient> ingredientsPizza = new List <Ingredient>(); foreach (var ingr in ingredients) { ingredientsPizza.Add(Ingredients.FirstOrDefault(i => i.Id == ingr)); } pizza.Id = Pizzas.Count(); pizza.Pate = patePizza; pizza.Ingredients = ingredientsPizza; Pizzas.Add(pizza); } return(RedirectToAction("Index")); } catch { return(View()); } }
private void InitializeData() { Ingredients = Pizza.IngredientsDisponibles; Pates = Pizza.PatesDisponibles; List <Ingredient> IngredientsPizza = new List <Ingredient>(); IngredientsPizza.Add(Ingredients.FirstOrDefault(x => x.Id == 1)); IngredientsPizza.Add(Ingredients.FirstOrDefault(x => x.Id == 2)); IngredientsPizza.Add(Ingredients.FirstOrDefault(x => x.Id == 7)); Pizzas.Add( new Pizza { Id = 1, Nom = "Reine", Ingredients = IngredientsPizza, Pate = Pates.FirstOrDefault(x => x.Id == 4) } ); }
private void InitialiserDatas() { IngredientsDisponibles.Add(new Ingredient { Id = 1, Nom = "Mozzarella" }); IngredientsDisponibles.Add(new Ingredient { Id = 2, Nom = "Jambon" }); IngredientsDisponibles.Add(new Ingredient { Id = 3, Nom = "Tomate" }); IngredientsDisponibles.Add(new Ingredient { Id = 4, Nom = "Oignon" }); IngredientsDisponibles.Add(new Ingredient { Id = 5, Nom = "Cheddar" }); IngredientsDisponibles.Add(new Ingredient { Id = 6, Nom = "Saumon" }); IngredientsDisponibles.Add(new Ingredient { Id = 7, Nom = "Champignon" }); IngredientsDisponibles.Add(new Ingredient { Id = 8, Nom = "Poulet" }); Pates.Add(new Pate { Id = 1, Nom = "Pate fine, base crême" }); Pates.Add(new Pate { Id = 2, Nom = "Pate fine, base tomate" }); Pates.Add(new Pate { Id = 3, Nom = "Pate épaisse, base crême" }); Pates.Add(new Pate { Id = 4, Nom = "Pate épaisse, base tomate" }); }