public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } catalog.AddPizza(Pizza); return(RedirectToPage("GetAllPizzas")); }
public IActionResult OnPost() { if (!ModelState.IsValid) { return(Page()); } _catalog.AddPizza(Pizza); //Adding the pizza property return(Redirect("GetAllPizzas")); }
public ActionResult AddPizza(Pizza pizza) { if (ModelState.IsValid) { bool result = _pizzaRepository.AddPizza(pizza); if (result) { return(RedirectToAction("Index", "Home")); } else { TempData["Failed"] = "Failed"; return(RedirectToAction("AddPizza", "Home")); } } return(View()); }
public IActionResult Post([FromBody] Pizza Pizza) //model binder of asp.net core will look for this parameter from request body { if (Pizza == null) { return(BadRequest("The pizza you are trying to add is empty")); } else { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } else { repo.AddPizza(Pizza); return(CreatedAtAction(nameof(Get), new { id = Pizza.ID }, Pizza)); } } }
public async Task <IActionResult> CreatePizza(PizzaViewModel model, List <Topping> toppings) { if (ModelState.IsValid) { Pizza pizza = new Pizza() { Name = model.Name, Price = model.Price, ImageURL = model.ImageURL, }; var result = _pizzaRepository.AddPizza(pizza); if (result) { return(RedirectToAction("Index", "Chef")); } else { } } return(View()); }
public ActionResult Create(IFormCollection collection, Models.Pizza pizza) { var custID = HttpContext.Session.GetInt32("CustomerId"); ViewBag.CustID = custID; if (custID == null) { ViewData["text"] = "Please Log In to place your order."; return(View()); } PizzaProject1.Library.Pizza dmc = new Pizza(); dmc.PizzaId = pizza.PizzaId; HttpContext.Session.SetInt32("PizzaId", pizza.PizzaId); dmc.Size = pizza.Size; dmc.Crust = pizza.Crust; dmc.PizzaAmount = 2; //pizza.PizzaAmount; dmc.OrderId = pizza.OrderId; dmc.Cost = pizza.PizzaCost(); try { // TODO: Add insert logic here var PizzaID = HttpContext.Session.GetInt32("PizzaId"); ViewBag.PizzaID = PizzaID; db.AddPizza(dmc); db.Save(); return(RedirectToAction("Index", "Topping")); } catch { return(View()); } }
public ActionResult Create(short SizeId, short CrustId, short T1, short T2, short T3, short T4, short T5, IFormCollection collection) { try { var uid = _mgr.GetUserId(this.User); var login = _context.GetLogins(uid); var order = _context.CurrentOrderLazy(login); var newPizza = new Pizza(order) { Size = new Size() { Id = SizeId }, Crust = new Crust() { Id = CrustId }, }; if (T1 != 0) { newPizza.AddTopping(new Topping() { Id = T1 }); } if (T2 != 0) { newPizza.AddTopping(new Topping() { Id = T2 }); } if (T3 != 0) { newPizza.AddTopping(new Topping() { Id = T3 }); } if (T4 != 0) { newPizza.AddTopping(new Topping() { Id = T4 }); } if (T5 != 0) { newPizza.AddTopping(new Topping() { Id = T5 }); } _context.AddPizza(login, newPizza); return(RedirectToAction(nameof(Index))); } catch (InvalidOperationException e) { TempData["ErrorString"] = e.Message; TempData["ReturnString"] = "/Order/Builder/Index"; return(Redirect("/Error")); } }
public void AddPizza(Pizza pizza) { _PizzaRepo.AddPizza(pizza); }
public void AddPizza(PizzaViewModel pizza) { _pizzaRepository.AddPizza(pizza.ToModel()); }