Esempio n. 1
0
        /// <summary>
        /// Map DBPizza => APizza
        /// Uses enum to determine which crust class to return.
        /// Note: premade pizza classes have constructors to set all variables properly.
        /// Therefore, they do not need any data tobe passed innto them.
        /// Custom pizza however only has 1 constructor that requires crust, size, and toppings
        /// to be passed into them.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public APizza Map(DBPizza entity)
        {
            APizza pizza;

            switch (entity.PIZZA)
            {
            case PIZZAS.CUSTOM:
                ACrust          crust    = mapperCrust.Map(entity.DBCrust);
                ASize           size     = mapperSize.Map(entity.DBSize);
                List <ATopping> toppings = new List <ATopping>();
                entity.DBPlacedToppings.ToList().ForEach(placedTopping => toppings.Add(mapperTopping.Map(placedTopping.Topping)));

                pizza = new CustomPizza(crust, size, toppings);
                break;

            case PIZZAS.HAWAIIAN:
                pizza = new HawaiianPizza(mapperSize.Map(entity.DBSize));
                break;

            case PIZZAS.MEAT:
                pizza = new MeatPizza(mapperSize.Map(entity.DBSize));
                break;

            case PIZZAS.VEGAN:
                pizza = new VeganPizza(mapperSize.Map(entity.DBSize));
                break;

            default:
                throw new ArgumentException("Pizza not recognized. Pizza could not be mapped properly");
            }

            pizza.CalculatePrice();
            pizza.ID = entity.ID;
            return(pizza);
        }
Esempio n. 2
0
        public void Test_HawaiianPizza_Fact()
        {
            // arrange
            Crust pcrust = new Crust("Regular", 0.25);
            Size  psize  = new Size("Large", 10.50);
            var   sut    = new HawaiianPizza(pcrust, psize);

            var nameExpected      = "Hawaiian Pizza";
            var sizeExpected      = "Large";
            var sizePriceExpected = 10.50;
            var crustExpected     = "Regular";
            var crustPriceExpeced = 0.25;

            // act
            var nameActual       = sut.Name;
            var sizeActual       = sut.Size.Name;
            var sizePriceActual  = sut.Size.Price;
            var crustActual      = sut.Crust.Name;
            var crustPriceActual = sut.Crust.Price;

            // assert
            Assert.Equal(nameExpected, nameActual);
            Assert.Equal(sizeExpected, sizeActual);
            Assert.Equal(sizePriceExpected, sizePriceActual);
            Assert.Equal(crustExpected, crustActual);
            Assert.Equal(crustPriceExpeced, crustPriceActual);
        }
Esempio n. 3
0
    public static IPizza CreatePizza(PizzaType pizzaType)
    {
        IPizza ret = null;

        switch (pizzaType)
        {
        case PizzaType.HamMushroom:
            ret = new HamAndMushroomPizza();

            break;

        case PizzaType.Deluxe:
            ret = new DeluxePizza();

            break;

        case PizzaType.Hawaiian:
            ret = new HawaiianPizza();

            break;

        default:
            throw new ArgumentException("The pizza type " + pizzaType + " is not recognized.");
        }

        return(ret);
    }
Esempio n. 4
0
        /// <summary>
        /// Map DBPizza => APizza
        /// Uses enum to determine which crust class to return.
        /// Note: premade pizza classes have constructors to set all variables properly.
        /// Therefore, they do not need any data tobe passed innto them.
        /// Custom pizza however only has 1 constructor that requires crust, size, and toppings
        /// to be passed into them.
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public APizza Map(DBPizza entity)
        {
            APizza pizza;

            switch (entity.PIZZA)
            {
            case Entities.EntityModels.PIZZAS.CUSTOM:
                Crust          crust    = mapperCrust.Map(entity.DBCrust);
                Size           size     = mapperSize.Map(entity.DBSize);
                List <Topping> toppings = new List <Topping>();
                entity.DBToppings.ForEach(Topping => toppings.Add(mapperTopping.Map(Topping)));

                pizza = new CustomPizza(crust, size, toppings);
                break;

            case Entities.EntityModels.PIZZAS.HAWAIIAN:
                pizza = new HawaiianPizza();
                break;

            case Entities.EntityModels.PIZZAS.MEAT:
                pizza = new MeatPizza();
                break;

            case Entities.EntityModels.PIZZAS.VEGAN:
                pizza = new VeganPizza();
                break;

            default:
                throw new ArgumentException("Size not recognized. Size could not be mapped properly");
            }

            return(pizza);
        }
Esempio n. 5
0
        public IActionResult OrderHawaiianPizza()
        {
            HawaiianPizza hawaiianPizza = new HawaiianPizza();

            ViewBag.OrderType = "Hawaiian Pizza";
            return(RedirectToAction("Index", "Order", new{ orderType = "Hawaiian Pizza", crust = hawaiianPizza.Crust, size = hawaiianPizza.Size, name = hawaiianPizza.Name, price = hawaiianPizza.Price }));
        }
Esempio n. 6
0
        public void Test_PizzaSize()
        {
            // arrange
            var sut = new HawaiianPizza(new LargeSize());

            // act
            var actual = sut.Size.Name;

            // assert
            Assert.Equal("Large", actual);
        }
Esempio n. 7
0
        public void PrintAllPizzas()
        {
            var meat = new MeatPizza();
            var veg  = new VeggiePizza();
            var flat = new HawaiianPizza();

            // var cust = new CustomPizza();
            System.Console.WriteLine("Here are the pizzas this store offers:");
            System.Console.WriteLine(meat.Name);
            System.Console.WriteLine(veg.Name);
            System.Console.WriteLine(flat.Name);
            // System.Console.WriteLine(cust.Name);
        }
        public ActionResult <APizza> GetPizzaInfo(PIZZAS PIZZA, SIZES SIZE)
        {
            APizza pizza;
            ASize  size;

            switch (SIZE)
            {
            case SIZES.SMALL:
                size = new SmallSize();
                break;

            case SIZES.MEDIUM:
                size = new MediumSize();
                break;

            case SIZES.LARGE:
                size = new LargeSize();
                break;

            default:
                return(StatusCode(400, "Size not recognized"));
            }

            switch (PIZZA)
            {
            case PIZZAS.MEAT:
                pizza = new MeatPizza(size);
                break;

            case PIZZAS.HAWAIIAN:
                pizza = new HawaiianPizza(size);
                break;

            case PIZZAS.VEGAN:
                pizza = new VeganPizza(size);
                break;

            case PIZZAS.CUSTOM:
                return(StatusCode(400, "You entered a custom pizza without providing the crust or toppings"));

            default:
                return(StatusCode(400, "Size not recognized"));
            }

            pizza.CalculatePrice();
            return(Ok(pizza));
        }
Esempio n. 9
0
        static void Main(string[] args)
        {
            Pizza pizza = new HawaiianPizza();

            Console.WriteLine("Standard pizza");
            Print(pizza);

            pizza = new CheeseDecorator(pizza);
            Console.WriteLine("Decorated with CheeseDecorator");
            Print(pizza);

            pizza = new HamDecorator(pizza);
            Console.WriteLine("Decorated with HamDecorator");
            Print(pizza);

            pizza = new CheeseDecorator(pizza);
            Console.WriteLine("Decorated with CheeseDecorator");
            Print(pizza);
        }
Esempio n. 10
0
        public static Pizza CreatePizza(string pizzaType)
        {
            Pizza pizza = null;

            switch (pizzaType)
            {
            case "Hawaiian":
                pizza = new HawaiianPizza();
                break;

            case "Cheese":
                pizza = new CheesePizza();
                break;

            default:
                break;
            }

            return(pizza);
        }
Esempio n. 11
0
        /// <summary>
        /// Map DBPizza => DBPizza
        /// Sets enum bassed off what pizza class was passed into it.
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public DBPizza Map(APizza model, PizzaDbContext context, bool update = false)
        {
            int   tempID   = model.ID;
            ASize tempSize = model.Size;

            switch (model.PIZZA)//if model is a preset pizza, throw everything away and set it to the preset
            {
            case PIZZAS.HAWAIIAN:
                model = new HawaiianPizza(tempSize);
                break;

            case PIZZAS.MEAT:
                model = new MeatPizza(tempSize);
                break;

            case PIZZAS.VEGAN:
                model = new VeganPizza(tempSize);
                break;

            case PIZZAS.CUSTOM:
                break;

            default:
                throw new ArgumentException("Pizza not recognized. Pizza could not be mapped properly");
            }

            model.Size = tempSize;
            model.ID   = tempID;//ensure id wasnt lost in the switch case

            DBPizza dbPizza = context.DBPizzas
                              .Include(pizza => pizza.DBCrust)
                              .Include(pizza => pizza.DBSize)
                              .Include(pizza => pizza.DBPlacedToppings)
                              .ThenInclude(placedTopping => placedTopping.Topping)
                              .FirstOrDefault(pizza => pizza.ID == model.ID) ?? new DBPizza();

            if (dbPizza.ID != 0 && !update)
            {
                return(dbPizza);
            }

            dbPizza.PIZZA   = model.PIZZA;
            dbPizza.DBCrust = mapperCrust.Map(model.Crust, context, update);
            dbPizza.DBSize  = mapperSize.Map(model.Size, context, update);
            List <DBTopping> mappedToppings = new List <DBTopping>();

            model.Toppings.ForEach(topping => mappedToppings.Add(mapperTopping.Map(topping, context, update)));
            dbPizza.DBPlacedToppings.Clear();

            foreach (var group in mappedToppings.GroupBy(topping => topping.TOPPING))
            {
                var firstTopping = group.Last();

                if (firstTopping is null)
                {
                    throw new ArgumentException("Something went wrong!");
                }

                DBPlacedTopping placedTopping = context.DBPlacedToppings
                                                .Include(placedTopping => placedTopping.Pizza).Include(placedTopping => placedTopping.Topping)
                                                .FirstOrDefault(placedTopping => placedTopping.Pizza.ID == dbPizza.ID &&
                                                                placedTopping.Topping.ID == firstTopping.ID) ?? new DBPlacedTopping();

                if (placedTopping.ID != 0 && !update)
                {
                    continue;
                }

                placedTopping.Pizza   = dbPizza;
                placedTopping.Topping = firstTopping;
                dbPizza.DBPlacedToppings.Add(placedTopping);
            }

            model.CalculatePrice();
            dbPizza.Price = model.Price;
            if (dbPizza.ID == 0)
            {
                context.DBPizzas.Add(dbPizza);
            }
            return(dbPizza);
        }
        public ActionResult <APizza> GetPizzaInfo(PIZZAS PIZZA, SIZES SIZE, CRUSTS CRUST, [FromQuery] List <TOPPINGS> TOPPING)
        {
            APizza          pizza;
            ASize           size;
            ACrust          crust;
            List <ATopping> toppings = new List <ATopping>();

            switch (SIZE)
            {
            case SIZES.SMALL:
                size = new SmallSize();
                break;

            case SIZES.MEDIUM:
                size = new MediumSize();
                break;

            case SIZES.LARGE:
                size = new LargeSize();
                break;

            default:
                return(StatusCode(400, "Size not recognized"));
            }

            switch (CRUST)
            {
            case CRUSTS.DEEPDISH:
                crust = new DeepDishCrust();
                break;

            case CRUSTS.STANDARD:
                crust = new StandardCrust();
                break;

            case CRUSTS.STUFFED:
                crust = new StuffedCrust();
                break;

            case CRUSTS.THIN:
                crust = new ThinCrust();
                break;

            default:
                return(StatusCode(400, "Crust not recognized"));
            }

            foreach (TOPPINGS toppingEnum in TOPPING)
            {
                switch (toppingEnum)
                {
                case TOPPINGS.BACON:
                    toppings.Add(new Bacon());
                    break;

                case TOPPINGS.CHICKEN:
                    toppings.Add(new Chicken());
                    break;

                case TOPPINGS.EXTRACHEESE:
                    toppings.Add(new ExtraCheese());
                    break;

                case TOPPINGS.GREENPEPPER:
                    toppings.Add(new GreenPepper());
                    break;

                case TOPPINGS.HAM:
                    toppings.Add(new Ham());
                    break;

                case TOPPINGS.NOCHEESE:
                    toppings.Add(new NoCheese());
                    break;

                case TOPPINGS.PINEAPPLE:
                    toppings.Add(new Pineapple());
                    break;

                case TOPPINGS.REDPEPPER:
                    toppings.Add(new RedPepper());
                    break;

                case TOPPINGS.SAUSAGE:
                    toppings.Add(new Sausage());
                    break;

                default:
                    return(StatusCode(400, "Topping not recognized"));
                }
            }
            pizza = new APizza
            {
                PIZZA    = PIZZA,
                Name     = Enum.GetName <PIZZAS>(PIZZA),
                Crust    = crust,
                Toppings = toppings
            };
            switch (PIZZA)
            {
            case PIZZAS.MEAT:
                pizza          = new MeatPizza(size);
                pizza.Crust    = crust;
                pizza.Toppings = toppings;
                break;

            case PIZZAS.HAWAIIAN:
                pizza          = new HawaiianPizza(size);
                pizza.Crust    = crust;
                pizza.Toppings = toppings;
                break;

            case PIZZAS.VEGAN:
                pizza          = new VeganPizza(size);
                pizza.Crust    = crust;
                pizza.Toppings = toppings;
                break;

            case PIZZAS.CUSTOM:
                pizza = new CustomPizza(crust, size, toppings);
                break;

            default:
                return(StatusCode(400, "Size not recognized"));
            }

            pizza.CalculatePrice();
            return(Ok(pizza));
        }
        /// <summary>
        /// Displays Pizza Menu for user
        /// </summary>
        /// <param name="c"></param>

        public static void PizzaMenu(List <APizza> c)
        {
            var ps = PizzaSingleton.Instance;

            ps.Seeding();

            System.Console.WriteLine("\n--------------------------");
            System.Console.WriteLine("Select a Pizza");
            System.Console.WriteLine("--------------------------");

            var pizzaSelCount = 1;

            foreach (var item in ps.Pizzas)
            {
                System.Console.WriteLine("{0}.) {1}", pizzaSelCount, item);
                pizzaSelCount += 1;
            }

            var userInput = System.Console.ReadLine();
            // First input check --> is it a number?
            var userChoice = inputValidInt(userInput);

            // Second input check --> is the input in range of the menu options?
            userChoice = inputValidRange(userChoice, ps.Pizzas.Count);

            var userPizzaChoice = ps.Pizzas[userChoice - 1].Name;

            //System.Console.WriteLine("\nPizza chosen: {0}", userPizzaChoice);

            switch (userPizzaChoice.ToLower())
            {
            case "custom pizza":
                var         crustChoice    = CrustMenu();
                var         sizeChoice     = SizeMenu();
                var         toppingsChoice = ToppingsMenu();
                CustomPizza cp             = new CustomPizza(crustChoice, sizeChoice, toppingsChoice);
                c.Add(cp);
                Console.WriteLine("\nA {0} {1} with {2} crust has been added to your cart!", cp.Size.Name, cp.Name, cp.Crust.Name);
                break;

            case "cheese pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                CheesePizza userPizza = new CheesePizza(crustChoice, sizeChoice);
                c.Add(userPizza);
                Console.WriteLine("\nA {0} {1} with {2} crust has been added to your cart!", userPizza.Size.Name, userPizza.Name, userPizza.Crust.Name);
                break;

            case "hawaiian pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                HawaiianPizza hp = new HawaiianPizza(crustChoice, sizeChoice);
                c.Add(hp);
                Console.WriteLine("\nA {0} {1} with {2} crust has been added to your cart!", hp.Size.Name, hp.Name, hp.Crust.Name);
                break;

            case "pepperoni pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                PepperoniPizza pp = new PepperoniPizza(crustChoice, sizeChoice);
                c.Add(pp);
                Console.WriteLine("\nA {0} {1} with {2} crust has been added to your cart!", pp.Size.Name, pp.Name, pp.Crust.Name);
                break;

            case "sausage pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                SausagePizza sp = new SausagePizza(crustChoice, sizeChoice);
                c.Add(sp);
                Console.WriteLine("\nA {0} {1} with {2} crust has been added to your cart!", sp.Size.Name, sp.Name, sp.Crust.Name);
                break;

            case "veggie pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                VeggiePizza vp = new VeggiePizza(crustChoice, sizeChoice);
                c.Add(vp);
                Console.WriteLine("\nA {0} {1} with {2} crust has been added to your cart!", vp.Size.Name, vp.Name, vp.Crust.Name);
                break;
            }
        }
Esempio n. 14
0
        public void Test_HawaiianIsCorrect()
        {
            var sut = new HawaiianPizza();

            Console.WriteLine(sut.Name, sut.Size, sut.Crust, sut.Sauce, sut.ToppingsString(), sut.Price);
        }
Esempio n. 15
0
        /// <summary>
        /// Displays Pizza Menu for user
        /// </summary>
        /// <param name="c"></param>

        public static void PizzaMenu(List <APizza> c)
        {
            var ps = PizzaSingleton.Instance;

            ps.Seeding();

            System.Console.WriteLine("\nSelect a Pizza");
            System.Console.WriteLine("--------------------------");

            var pizzaSelCount = 1;

            foreach (var item in ps.Pizzas)
            {
                System.Console.WriteLine(pizzaSelCount + ".) " + item);
                pizzaSelCount += 1;
            }

            var userChoice      = int.Parse(System.Console.ReadLine());
            var userPizzaChoice = ps.Pizzas[userChoice - 1].Name;

            System.Console.WriteLine("Pizza chosen: {0}", userPizzaChoice);



            switch (userPizzaChoice.ToLower())
            {
            case "custom pizza":
                var crustChoice = CrustMenu();
                var sizeChoice  = SizeMenu();
                ToppingsMenu();
                CustomPizza cp = new CustomPizza();
                c.Add(cp);
                break;

            case "cheese pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                CheesePizza userPizza = new CheesePizza(crustChoice, sizeChoice);
                c.Add(userPizza);
                break;

            case "hawaiian pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                HawaiianPizza hp = new HawaiianPizza(crustChoice, sizeChoice);
                c.Add(hp);
                break;

            case "pepperoni pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                PepperoniPizza pp = new PepperoniPizza(crustChoice, sizeChoice);
                c.Add(pp);
                break;

            case "sausage pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                SausagePizza sp = new SausagePizza(crustChoice, sizeChoice);
                c.Add(sp);
                break;

            case "veggie pizza":
                crustChoice = CrustMenu();
                sizeChoice  = SizeMenu();
                VeggiePizza vp = new VeggiePizza(crustChoice, sizeChoice);
                c.Add(vp);
                break;
            }
        }
Esempio n. 16
0
        public List <APizzaModel> SelectPizzas()
        {
            bool Leave = true;
            List <APizzaModel>  Pizzas   = new List <APizzaModel>();
            APizzaModel         test     = new MeatPizza();
            GenericPizzaFactory _factory = new GenericPizzaFactory();

            do
            {
                PrintAllPizzas();
                System.Console.WriteLine("Select a pizza, enter 9 to finish selecting");
                int.TryParse(Console.ReadLine(), out int input);
                switch (input)
                {
                case 1:
                {
                    var size  = SelectSize();
                    var crust = SelectCrust();
                    var pizza = new MeatPizza(size, crust);
                    Pizzas.Add(pizza);
                    break;
                }

                case 2:
                {
                    var size  = SelectSize();
                    var crust = SelectCrust();
                    var pizza = new VeggiePizza(size, crust);
                    Pizzas.Add(pizza);
                    break;
                }

                case 3:
                {
                    var size  = SelectSize();
                    var crust = SelectCrust();
                    var pizza = new HawaiianPizza(size, crust);
                    Pizzas.Add(pizza);
                    break;
                }

                case 4:
                {
                    // var pizza = _factory.Make<CustomPizza>();
                    // pizza.AddSize(SelectSize());
                    // pizza.AddCrust(SelectCrust());
                    // Pizzas.Add(pizza);
                    break;
                }

                case 9:
                {
                    Leave = false;
                    break;
                }

                default:
                {
                    Console.WriteLine("Please enter a valid choice");
                    break;
                }
                }
            } while (Leave);
            return(Pizzas);
        }