コード例 #1
0
        public ActionResult CreatePizza(string size, string name, bool?bacon, bool?bbq, bool?cheese, bool?mushroom, bool?onion, bool?pepperoni, bool?pepper, bool?pineapple, bool?sausage, bool?shrimp, int amt, bool?deliver, InfoViewModel infoView)
        {
            bool isNum = IsNumber(amt);

            if (ModelState.IsValid && !string.IsNullOrEmpty(size) && isNum)
            {
                double totalCost;
                Pizza  aPizza = null;

                //Switch statement for the size of the pizza
                switch (size)
                {
                case "Small":
                    aPizza = new Small();
                    break;

                case "Medium":
                    aPizza = new Medium();
                    break;

                case "Large":
                    aPizza = new Large();
                    break;
                }

                //If the topping was selected then it is added to the pizza
                if (bacon == true)
                {
                    aPizza = new Bacon(aPizza);
                }

                if (bbq == true)
                {
                    aPizza = new BBQ(aPizza);
                }

                if (cheese == true)
                {
                    aPizza = new ExCheese(aPizza);
                }

                if (mushroom == true)
                {
                    aPizza = new Mushroom(aPizza);
                }

                if (onion == true)
                {
                    aPizza = new Onion(aPizza);
                }

                if (pepperoni == true)
                {
                    aPizza = new Pepperoni(aPizza);
                }

                if (pepper == true)
                {
                    aPizza = new Peppers(aPizza);
                }

                if (pineapple == true)
                {
                    aPizza = new Pineapple(aPizza);
                }

                if (sausage == true)
                {
                    aPizza = new Sausage(aPizza);
                }

                if (shrimp == true)
                {
                    aPizza = new Shrimp(aPizza);
                }


                //Created a variable to contain and manipulate the cost
                totalCost = aPizza.GetCost();

                infoView.Delivery = deliver;

                if (Session["cart"] == null)
                {
                    List <CartItem> cart = new List <CartItem>
                    {
                        new CartItem {
                            ID        = 1,
                            Pizza     = aPizza,
                            Quant     = amt,
                            ViewModel = infoView
                        }
                    };
                    Session["info"]  = infoView;
                    Session["cart"]  = cart;
                    Session["Total"] = cart.Sum(item => item.Pizza.GetCost() * item.Quant);
                }
                else
                {
                    List <CartItem> cart  = (List <CartItem>)Session["cart"];
                    int             index = IsExist(aPizza);
                    if (index != -1)
                    {
                        cart[index].Quant++;
                    }
                    else
                    {
                        int currentID = cart.Count();
                        cart.Add(new CartItem {
                            ID = currentID, Pizza = aPizza, Quant = amt, ViewModel = infoView
                        });
                    }

                    Session["info"]  = infoView;
                    Session["cart"]  = cart;
                    Session["Total"] = cart.Sum(item => item.Pizza.GetCost() * item.Quant);
                }



                //Method sends order to database
                //aConnection.InsertPizzaOrder(aPizza, totalCost, name, amt, deliver, addy, city, zip, time);

                //Adds everything to a ViewBag to send to confirmation page
                //ViewBag.APizza = aPizza;
                //ViewBag.Total = totalCost;
                //ViewBag.Name = name;
                //ViewBag.Amt = amt;
                //ViewBag.Deliver = deliver;
                //ViewBag.Addy = addy;
                //ViewBag.City = city;
                //ViewBag.Zip = zip;
                //ViewBag.Time = time;

                return(RedirectToAction("DisplayCart"));
            }
            else
            {
                if (string.IsNullOrEmpty(size))
                {
                    TempData["Amt"]  = "The amount must be a number";
                    TempData["Size"] = "A size must be selected";
                }

                return(View("CreatePizzaForm", infoView));
            }
        }
コード例 #2
0
        public ActionResult AddMorePizza(string size, string name, bool?bacon, bool?bbq, bool?cheese, bool?mushroom, bool?onion, bool?pepperoni, bool?pepper, bool?pineapple, bool?sausage, bool?shrimp, int amt)
        {
            if (!string.IsNullOrEmpty(size))
            {
                double totalCost;
                Pizza  aPizza = null;

                //Switch statement for the size of the pizza
                switch (size)
                {
                case "Small":
                    aPizza = new Small();
                    break;

                case "Medium":
                    aPizza = new Medium();
                    break;

                case "Large":
                    aPizza = new Large();
                    break;
                }

                //If the topping was selected then it is added to the pizza
                if (bacon == true)
                {
                    aPizza = new Bacon(aPizza);
                }

                if (bbq == true)
                {
                    aPizza = new BBQ(aPizza);
                }

                if (cheese == true)
                {
                    aPizza = new ExCheese(aPizza);
                }

                if (mushroom == true)
                {
                    aPizza = new Mushroom(aPizza);
                }

                if (onion == true)
                {
                    aPizza = new Onion(aPizza);
                }

                if (pepperoni == true)
                {
                    aPizza = new Pepperoni(aPizza);
                }

                if (pepper == true)
                {
                    aPizza = new Peppers(aPizza);
                }

                if (pineapple == true)
                {
                    aPizza = new Pineapple(aPizza);
                }

                if (sausage == true)
                {
                    aPizza = new Sausage(aPizza);
                }

                if (shrimp == true)
                {
                    aPizza = new Shrimp(aPizza);
                }


                //Created a variable to contain and manipulate the cost
                totalCost = aPizza.GetCost();

                if (Session["cart"] == null)
                {
                    List <CartItem> cart = new List <CartItem>
                    {
                        new CartItem {
                            ID        = 1,
                            Pizza     = aPizza,
                            Quant     = amt,
                            ViewModel = (InfoViewModel)Session["info"]
                        }
                    };
                    Session["cart"]  = cart;
                    Session["Total"] = cart.Sum(item => item.Pizza.GetCost() * item.Quant);
                }
                else
                {
                    List <CartItem> cart  = (List <CartItem>)Session["cart"];
                    int             index = IsExist(aPizza);
                    if (index != -1)
                    {
                        cart[index].Quant++;
                    }
                    else
                    {
                        int currentID = cart.Count();
                        cart.Add(new CartItem {
                            ID = currentID, Pizza = aPizza, Quant = amt, ViewModel = (InfoViewModel)Session["info"]
                        });
                    }
                    Session["cart"]  = cart;
                    Session["Total"] = cart.Sum(item => item.Pizza.GetCost() * item.Quant);
                }


                return(RedirectToAction("DisplayCart"));
            }
            else
            {
                if (string.IsNullOrEmpty(size))
                {
                    TempData["Amt"]  = "The amount must be a number";
                    TempData["Size"] = "A size must be selected";
                }

                return(View("AddMorePizzaForm"));
            }
        }