Ejemplo n.º 1
0
        public static void Menu(Order cart)
        {
            bool exit = false;

            while (!exit)
            {
                List <string> toppings   = new List <string>();
                var           pizzaPrice = 8.0m;                        // fix it for now

                string pizzaType = GetPizzaType(cart, toppings, pizzaPrice, ref exit);

                var pizzaSize     = "";
                var pizzaCrust    = "";
                var toppings_list = "";

                if (pizzaType != "")
                {
                    pizzaSize     = GetPizzaSize(cart, ref exit);       // Ask for the size of pizza
                    pizzaCrust    = GetPizzaCrust(cart, ref exit);      // Ask for the desired crust type
                    toppings_list = String.Join(", ", toppings.ToArray());



                    System.Console.WriteLine($"Pizza type is {pizzaType}, size = {pizzaSize}, toppings = {toppings_list}, price = {pizzaPrice}");

                    cart.CreatePizza(pizzaType, pizzaSize, pizzaCrust, toppings, pizzaPrice); // add the pizza to the order

                    var   repository = new PizzaRepository();
                    Pizza lastPizza  = cart.Pizzas.Last();
                    repository.Create(lastPizza);

                    System.Console.WriteLine($"We added a {pizzaSize}, {pizzaCrust}, {pizzaType} pizza to your order.\n");
                }
            }
Ejemplo n.º 2
0
 /// <param name="pizza"></param>
 public ActionResult Create(Pizza pizza)
 {
     try
     {
         m_PizzaRepository.Create(pizza);
         return(View("Success"));
     }
     catch (Exception e)
     {
         return(View("Error"));
     }
 }
Ejemplo n.º 3
0
        static void Menu(Order cart)
        {
            var exit   = false;
            var pr     = new PizzaRepository();
            var num    = 1;
            var total  = 0.0;
            var ototal = 0.0;

            do
            {
                System.Console.WriteLine("Would you like to place an order");
                System.Console.WriteLine("1 for yes");
                System.Console.WriteLine("2 for no");
                System.Console.WriteLine("");
                ototal += total;
                System.Console.WriteLine("Your current total is: $" + ototal);
                System.Console.WriteLine("");
                var placeOrder = Console.ReadLine();
                int confirm;
                int.TryParse(placeOrder, out confirm);

                if (confirm == 1)
                {
                    exit = false;
                }
                else
                {
                    System.Console.WriteLine("Please procceed to checkout");
                    exit = true;
                    break;
                }


                System.Console.WriteLine("Please select which size you would like:");
                System.Console.WriteLine("1 for small at $2.50");
                System.Console.WriteLine("2 for medium at $5.00");
                System.Console.WriteLine("3 for large at $10.00");
                System.Console.WriteLine("");
                var Answer = Console.ReadLine();
                var s      = new Size(Answer);
                total = s.Price;

                System.Console.WriteLine(s._size);
                System.Console.WriteLine("The cost of your pizza will be " + s.Price);
                System.Console.WriteLine("");

                System.Console.WriteLine("Please select which crust you would like:");
                System.Console.WriteLine("1 for regular");
                System.Console.WriteLine("2 for stuffed crust");
                System.Console.WriteLine("3 for thin crust");
                System.Console.WriteLine("");
                var answer = Console.ReadLine();
                var c      = new Crust(answer);
                System.Console.WriteLine(c._crust);
                System.Console.WriteLine("");



                Startup.PrintMenu();

                int select;

                int.TryParse(Console.ReadLine(), out select);
                num++;

                switch (select)
                {
                case 1:
                    var pizzas = new Pizza()
                    {
                        Name  = "Extra Cheese Pizza",
                        crust = new Crust(answer)
                        {
                            Name = c._crust
                        },
                        size = new Size(Answer)
                        {
                            Name = s._size
                        },
                        //toppings = new List<Toppings>() {new Toppings(select) {Name = "Cheese"}}
                    };
                    pr.Create(pizzas);
                    System.Console.WriteLine("Cheese pizza added to cart");
                    System.Console.WriteLine();
                    break;

                case 2:
                    pizzas = new Pizza()
                    {
                        Name  = "Pepperoni Pizza",
                        crust = new Crust(answer)
                        {
                            Name = c._crust
                        },
                        size = new Size(Answer)
                        {
                            Name = s._size
                        },
                        //toppings = new List<Toppings>() {new Toppings(select) {Name = "Pepperoni"}}
                    };
                    pr.Create(pizzas);
                    System.Console.WriteLine("Pepperoni pizza added to cart");
                    System.Console.WriteLine();
                    break;

                case 3:
                    pizzas = new Pizza()
                    {
                        Name  = "Hawaiian Pizza",
                        crust = new Crust(answer)
                        {
                            Name = c._crust
                        },
                        size = new Size(Answer)
                        {
                            Name = s._size
                        },
                        //toppings = new List<Toppings>() { new Toppings(select) { Name = "Ham,Pineapple" } }
                    };
                    pr.Create(pizzas);
                    System.Console.WriteLine("Hawaiian pizza added to cart");
                    System.Console.WriteLine();
                    break;

                case 4:
                    pizzas = new Pizza()
                    {
                        Name  = "Sausage Pizza",
                        crust = new Crust(answer)
                        {
                            Name = c._crust
                        },
                        size = new Size(Answer)
                        {
                            Name = s._size
                        },
                        toppings = new List <Toppings>()
                        {
                            new Toppings(select)
                            {
                                Name = "Sausage"
                            }
                        }
                    };
                    pr.Create(pizzas);
                    System.Console.WriteLine("Sausage pizza added to cart");
                    System.Console.WriteLine();
                    break;

                case 5:
                    foreach (var item in pr.ReadAll(answer, Answer))
                    {
                        System.Console.WriteLine(item);
                    }
                    break;
                }
                System.Console.WriteLine();
                if (num >= 50)
                {
                    exit = true;
                    break;
                }
                if (total >= 250)
                {
                    exit = true;
                    break;
                }
            } while (!exit);
        }
Ejemplo n.º 4
0
        // [ValidateAntiForgeryToken]
        public IActionResult Post(PizzaViewModel pizzaViewModel, int id) //model binding
        {
            var return_view = "";

            switch (id)
            {
            case 1:       // set return view for standard pizza orders

                return_view = "OrderStandard";
                break;

            case 2:       // set return view for custom pizza orders
                pizzaViewModel.Type = "Custom";
                return_view         = "OrderCustom";
                break;

            default:
                break;
            }
            ;

            if (ModelState.IsValid)                //  what is the validation? (add to viewmodel)
            {
                var        p = new PizzaFactory(); // use dependency injection
                PizzaModel domainPizzaModel = new PizzaModel();
                domainPizzaModel = p.Create();     // factory-created Domain PizzaModel

                if (pizzaViewModel.Types.Contains(pizzaViewModel.Type) || pizzaViewModel.Type == "Custom")
                {
                    switch (id)
                    {
                    case 1:                                                                                        //standard pizza chosen
                        pizzaViewModel.SelectedToppings.Clear();
                        pizzaViewModel.SelectedToppings.AddRange(pizzaViewModel.ToppingSets[pizzaViewModel.Type]); // add topping sets based on chosen pizza type
                        break;

                    case 2: //custom pizza chosen
                        if (pizzaViewModel.SelectedToppings.Contains("dummy"))
                        {
                            return(View(return_view, pizzaViewModel));      // no toppings were chosen at all, return to custom pizza order page
                        }
                        break;

                    default:
                        break;
                    }

                    var pricepertopping = 1.0m;
                    switch (id)
                    {
                    case 1:   // set prices for standard pizza orders
                        domainPizzaModel.Price = pizzaViewModel.Prices[pizzaViewModel.Type];
                        break;

                    case 2:                                                        // set prices for custom pizza orders
                        domainPizzaModel.Price  = pizzaViewModel.Prices["Cheese"]; //cheapest
                        domainPizzaModel.Price += pizzaViewModel.SelectedToppings.Count * pricepertopping;
                        break;

                    default:
                        break;
                    }
                    ;
                }
                else
                {
                    domainPizzaModel.Price = pizzaViewModel.Prices["Cheese"]; //cheapest
                    pizzaViewModel.SelectedToppings.AddRange(pizzaViewModel.ToppingSets["Cheese"]);
                }

                // bind PizzaViewModel to Domain PizzaModel
                domainPizzaModel.Name = pizzaViewModel.Type;

                var newC = new CrustModel();
                newC.Name = pizzaViewModel.Crust;
                domainPizzaModel.Crust = newC;

                var newS = new SizeModel();
                newS.Name             = pizzaViewModel.Size;
                domainPizzaModel.Size = newS;

                foreach (var t in pizzaViewModel.SelectedToppings)
                {
                    var newToppings = new List <ToppingModel>();
                    var newTopping  = new ToppingModel();
                    newTopping.Name = t;
                    domainPizzaModel.Toppings.Add(newTopping);
                }

                var repo_pizza = new PizzaRepository();
                repo_pizza.Create(domainPizzaModel, _db);

                return_view = "ThankYou";
                return(View(return_view));
            }


            return(View(return_view, pizzaViewModel));
        }
Ejemplo n.º 5
0
 public Pizza Post([FromBody] Pizza pizza)
 {
     return(_repo.Create(pizza));
 }
Ejemplo n.º 6
0
        static void Menu3(Order cart) //Order datatype called cart
        {
            var exit = false;

            do
            {
                Console.WriteLine("Select 1 for Cheese Pizza");
                Console.WriteLine("Select 2 for Pepperoni Pizza");
                Console.WriteLine("Select 3 for Hawaiian Pizza");
                Console.WriteLine("Select 4 for Custom Pizza");
                Console.WriteLine("Select 5 to view cart");
                Console.WriteLine("Select 6 to exit");

                int select;
                int.TryParse(Console.ReadLine(), out select);
                //reads the input put in by user

                switch (select)
                {
                case 1:
                    var Pizza = new Pizza(new Size {
                    }, new Crust {
                    }, new List <Toppings> {
                        new Toppings("Cheese")
                    }, 5);
                    SizeMenu(Pizza);
                    CrustMenu(Pizza);
                    Console.WriteLine("added Cheese Pizza");
                    cart.CreatePizza(Pizza);

                    break;

                case 2:
                    Pizza = new Pizza(new Size {
                    }, new Crust {
                    }, new List <Toppings> {
                        new Toppings("Pepperoni")
                    }, 5);
                    SizeMenu(Pizza);
                    CrustMenu(Pizza);
                    Console.WriteLine("added Pepperoni Pizza");
                    cart.CreatePizza(Pizza);
                    break;

                case 3:
                    Pizza = new Pizza(new Size {
                    }, new Crust {
                    }, new List <Toppings> {
                        new Toppings("Hawaiian")
                    }, 5);
                    SizeMenu(Pizza);
                    CrustMenu(Pizza);
                    Console.WriteLine("added Hawaiian Pizza");
                    cart.CreatePizza(Pizza);
                    break;

                case 4:
                    Pizza = new Pizza(new Size {
                    }, new Crust {
                    }, new List <Toppings> {
                        new Toppings("Cheese")
                    }, 5);
                    SizeMenu(Pizza);
                    CrustMenu(Pizza);
                    CustomMenu(Pizza);
                    cart.CreatePizza(Pizza);
                    break;

                case 5:
                    DisplayCart(cart);
                    break;

                case 6:
                    // var fm = new FileManager();
                    // fm.Write(cart);
                    PizzaRepository pr = new PizzaRepository();
                    foreach (var pizza in cart.Pizzas)
                    {
                        pr.Create(pizza);
                    }
                    Console.WriteLine("Thank you, goodbye!");
                    exit = true;
                    break;

                case 7:
                    var fmr = new FileManager();
                    DisplayCart(fmr.Read());
                    break;
                }
            } while (!exit);
        }