コード例 #1
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            catalog.AddPizza(Pizza);

            return(RedirectToPage("GetAllPizzas"));
        }
コード例 #2
0
        public IActionResult OnPost()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }


            _catalog.AddPizza(Pizza); //Adding the pizza property
            return(Redirect("GetAllPizzas"));
        }
コード例 #3
0
 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());
 }
コード例 #4
0
 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));
         }
     }
 }
コード例 #5
0
        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());
        }
コード例 #6
0
        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());
            }
        }
コード例 #7
0
 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"));
     }
 }
コード例 #8
0
 public void AddPizza(Pizza pizza)
 {
     _PizzaRepo.AddPizza(pizza);
 }
コード例 #9
0
 public void AddPizza(PizzaViewModel pizza)
 {
     _pizzaRepository.AddPizza(pizza.ToModel());
 }