//[ValidateAntiForgeryToken] public IActionResult FinishPizza(PizzaViewModel pModel) { //if (ModelState.IsValid) //{ // return Redirect("user/home"); //} OrderRepository oRepo = new OrderRepository(_db); PizzaRepository pRepo = new PizzaRepository(_db); CrustRepository cRepo = new CrustRepository(_db); SizeRepository sRepo = new SizeRepository(_db); ToppingRepository tRepo = new ToppingRepository(_db); PizzaFactory pf = new PizzaFactory(); Pizza p = pf.CreateCustom(); p.Crust = cRepo.GetCrustByName(pModel.Crust); p.Size = sRepo.GetSizeByName(pModel.Size); p.Order = oRepo.Get2(pModel.OrderId); foreach (SelectedTopping st in pModel.SelectedToppings) { if (st.IsSelected) { p.PizzaToppings.Add(new PizzaTopping() { Topping = tRepo.GetToppingByName(st.Name), Pizza = p }); } } p.Price = p.GetPrice(); pRepo.Add(p); pModel.Order = oRepo.Get(pModel.OrderId); return(View("Order", pModel)); }
public ActionResult AddPizza(AddPizzaModel model) { var ingredients = HttpContext.Request.Form.Get("Ingredients").Split(',').Select(int.Parse); foreach (var ingredient in ingredients) { model.Ingredients.Add(new PizzaIngredient { IngredientId = ingredient }); } _pizzaRepository.Add(model.Name, model.Size, model.Thickness, model.Ingredients); return(RedirectToAction("Menu", "List")); }
public void ShouldNotAddExistingPizza() { var numberOfPizzasBeforeAdd = _sut.Get().Count(); var existingPizza = _sut.Get().First(); _sut.Add(existingPizza); var numberOfPizzasAfterAdd = _sut.Get().Count(); Assert.Equal(numberOfPizzasBeforeAdd, numberOfPizzasAfterAdd); }
public IActionResult Post([FromBody] Pizza pizza) { _pizzaRepository.Add(pizza); var maybePizza = _pizzaRepository.Get(pizza.Name); if (maybePizza.Any()) { return(new ContentResult { Content = $"/pizzas/{maybePizza.First().Id}", StatusCode = 201 }); } return(new ContentResult { Content = "Duplicate pizza name/id", StatusCode = 409 }); }
public async void TestPizzaRepositoryAdd() { await _connection.OpenAsync(); await dbo.Database.EnsureCreatedAsync(); PizzaModel tempPizza = new PizzaModel() { Crust = new CrustModel { Name = "garlic", Description = "delicousness" }, Size = new SizeModel { Name = "large", Diameter = 16 }, Toppings = new System.Collections.Generic.List <ToppingsModel> { new ToppingsModel { Name = "onions", Description = "they have layers" } }, Name = "shrek", Description = "right form the swamp", SpecialPizza = true }; PizzaRepository PR = new PizzaRepository(dbo); PR.Add(tempPizza); Assert.NotNull(dbo.Pizzas.FirstOrDefaultAsync(pizza => pizza.Name == tempPizza.Name)); }