Beispiel #1
0
        public override BlankPizza GetPizza()
        {
            BlankPizza newPizza = pizza;

            pizza = new Pepperoni();
            return(newPizza);
        }
        public override string ToString()
        {
            var sb = new StringBuilder();

            sb.AppendLine($"---- {Name} ----");

            if (Dough != null)
            {
                sb.AppendLine(Dough.ToString());
            }
            if (Sauce != null)
            {
                sb.AppendLine(Sauce.ToString());
            }
            if (Cheese != null)
            {
                sb.AppendLine(Cheese.ToString());
            }
            if (Veggies != null)
            {
                sb.AppendLine(string.Join(",", Veggies));
            }
            if (Clam != null)
            {
                sb.AppendLine(Clam.ToString());
            }
            if (Pepperoni != null)
            {
                sb.AppendLine(Pepperoni.ToString());
            }

            return(sb.ToString());
        }
Beispiel #3
0
        public void Test_Pepperoni()
        {
            var sut = new Pepperoni();

            Assert.True(sut.Name.Equals("Pepperoni"));
            Assert.True(sut.Price.Equals(3.00m));
        }
Beispiel #4
0
        public override AbstractPizza Create()
        {
            AbstractPizza result = pizza;

            pizza = new Pepperoni();
            return(result);
        }
Beispiel #5
0
 public override string ToString()
 {
     return($"Dough: {Dough.GetType().Name}\n" +
            $"Sauce: {Sauce.GetType().Name}\n" +
            $"Cheese: {Cheese.GetType().Name}\n" +
            $"Pepperoni: {Pepperoni.GetType().Name}\n");
 }
Beispiel #6
0
 public Pizza()
 {
     name      = "";
     dough     = new Dough();
     sauce     = new Sauce();
     cheese    = new Cheese();
     pepperoni = new Pepperoni();
     clams     = new Clams();
     veggies   = new List <Veggies>();
 }
        public static void DecoratorCommand()
        {
            Pizza mypizza = new ThickCrust();

            mypizza = new Pepperoni(mypizza);
            mypizza = new Sausage(mypizza);
            Console.WriteLine("This is the decorator pattern. It allows behaviors to be added to an existing object dynamically during runtime.");
            Console.WriteLine("Here we use a decorator pattern to make a pizza, and add things to it, and then to tell us it's cost.");
            Console.WriteLine($"Pizza costs: {mypizza.cost()}");
            Console.ReadLine();
        }
Beispiel #8
0
        public override void Prepare()
        {
            Pepperoni = ingredientFactory.CreatePepperoni();
            Dough     = ingredientFactory.CreateDough();
            Veggies   = ingredientFactory.CreateVeggies();

            Console.WriteLine($"Preparing {Name}");
            Console.WriteLine(Pepperoni.GetType().ToString());
            Console.WriteLine(Dough.GetType().ToString());

            foreach (var item in Veggies)
            {
                Console.WriteLine(item.GetType().ToString());
            }
        }
Beispiel #9
0
        public override string ToString()
        {
            var result = new StringBuilder();

            result.AppendLine("---- " + Name + " ----");
            if (Dough != null)
            {
                result.AppendLine(Dough.ToString());
            }
            if (Sauce != null)
            {
                result.AppendLine(Sauce.ToString());
            }
            if (Cheese != null)
            {
                result.AppendLine(Cheese.ToString());
            }
            if (Veggies != null)
            {
                bool isFirst = true;
                foreach (var veggy in Veggies)
                {
                    if (isFirst)
                    {
                        result.Append(veggy.ToString());
                        isFirst = false;
                    }
                    else
                    {
                        result.Append(", ");
                        result.Append(veggy.ToString());
                    }
                }
                result.AppendLine();
            }
            if (Pepperoni != null)
            {
                result.AppendLine(Pepperoni.ToString());
            }
            if (Clams != null)
            {
                result.AppendLine(Clams.ToString());
            }
            return(result.ToString());
        }
Beispiel #10
0
    public override IPizza GetPizza(ToppingType tType)
    {
        IPizza currentPizza;

        switch (tType)
        {
        case ToppingType.Cheese:
            IPizza cheeseZa = new CheesePizza();
            currentPizza = cheeseZa;
            return(currentPizza);

        case ToppingType.Pepperoni:
            IPizza pepZa = new CheesePizza();
            pepZa        = new Pepperoni(pepZa);
            currentPizza = pepZa;
            return(currentPizza);

        case ToppingType.Sausage:
            IPizza sausageZa = new CheesePizza();
            sausageZa    = new Sausage(sausageZa);
            currentPizza = sausageZa;
            return(currentPizza);

        case ToppingType.Supreme:
            IPizza supremeZa = new CheesePizza();
            supremeZa    = new Supreme(supremeZa);
            currentPizza = supremeZa;
            return(currentPizza);

        case ToppingType.BbqChicken:
            IPizza bbqZa = new CheesePizza();
            bbqZa        = new BBQChicken(bbqZa);
            currentPizza = bbqZa;
            return(currentPizza);

        case ToppingType.Margherita:
            IPizza margZa = new CheesePizza();
            margZa       = new Margherita(margZa);
            currentPizza = margZa;
            return(currentPizza);
        }
        return(null);
    }
Beispiel #11
0
        public override string ToString()
        {
            var result = new StringBuilder();

            result.AppendLine("---- " + Name + " ----");
            if (Dough != null)
            {
                result.AppendLine(Dough.ToString());
            }
            if (Sauce != null)
            {
                result.AppendLine(Sauce.ToString());
            }
            if (Cheese != null)
            {
                result.AppendLine(Cheese.ToString());
            }
            if (Veggies != null)
            {
                for (int i = 0; i < Veggies.Length; i++)
                {
                    result.Append(Veggies[i].ToString());
                    if (i < Veggies.Length - 1)
                    {
                        result.Append(", ");
                    }
                }
                result.Append("\n");
            }
            if (Clam != null)
            {
                result.AppendLine(Clam.ToString());
            }
            if (Pepperoni != null)
            {
                result.AppendLine(Pepperoni.ToString());
            }

            return(result.ToString());
        }
Beispiel #12
0
 public override void Prepare()
 {
     Console.WriteLine("Preparing {0}", Name);
     Dough     = pizzaIngredientFactory.CreateDough();
     Sauce     = pizzaIngredientFactory.CreateSauce();
     Cheese    = pizzaIngredientFactory.CreateCheese();
     Pepperoni = pizzaIngredientFactory.CreatePepperoni();
     Console.WriteLine("Ingredients: Dough: {0} - Sauce: {1} - Cheese: {2} - Pepperoni: {3}", Dough.ToString(), Sauce.ToString(), Cheese.ToString(), Pepperoni.ToString());
 }
Beispiel #13
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));
            }
        }
Beispiel #14
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"));
            }
        }
Beispiel #15
0
 public PepperoniBuilder()
 {
     pizza = new Pepperoni();
 }