public bool SubmitUserOrder(PizzaOrder newOrder)
        {
            try{
                // submit order object into db
                _dbConnection.OrderTable.Add(new OrderTable {
                    UserId         = newOrder.UserID,
                    LocationId     = newOrder.OrderShopLocationID,
                    OrderTotalCost = newOrder.GetTotalOrderCost(),
                    PizzaCount     = newOrder.GetTotalPizzaCount()
                });
                _dbConnection.SaveChanges();
            }catch (System.Exception ex) {
                return(false);
            }

            try{
                int currentOrderID = _dbConnection.OrderTable.ToList()
                                     [_dbConnection.OrderTable.ToList().Count - 1].OrderId;

                // submit pizzas to db and link to order
                foreach (var pizza in newOrder.OrderItems)
                {
                    int CurrentPizzaID = PizzaRecipesDataRetriever.GetInstance().AddPizzaToDB(pizza);
                    _dbConnection.PizzasInOrder.Add(new PizzasInOrder {
                        OrderId = currentOrderID,
                        PizzaId = CurrentPizzaID
                    });
                    _dbConnection.SaveChanges();
                }
            }catch (System.Exception ex) {
                return(false);
            }
            return(true);
        }
Example #2
0
        private static void PizzaSelectionMenu()
        {
            CurrentPizzaOrder = new PizzaOrder(CurrentShopLocation.ShopID, ActiceUser.UserId);
            System.Console.WriteLine("Step-2: Pizza(s) Selection: ");
            bool addMorePizzas = true;

            while (addMorePizzas)
            {
                System.Console.WriteLine("1- Signiture Pizza");
                System.Console.WriteLine("2- Custom Pizza");
                System.Console.Write("Pizza Choice: ");
                int  pizzaChoice    = Convert.ToInt32(Console.ReadLine());
                bool pizzaAddedFlag = false;

                switch (pizzaChoice)
                {
                case 1:
                    System.Console.WriteLine("Choose one of the following recipes: ");
                    DisplayPizzaRecipes(PizzaRecipesDataRetriever.GetInstance().PizzaRecipesList);
                    System.Console.Write("Recipe Choice: ");
                    int recipeChoice = Convert.ToInt32(Console.ReadLine());

                    IPizza newPizza = PizzaRecipesDataRetriever.GetInstance().PizzaRecipesList[recipeChoice - 1];
                    newPizza       = PizzaSizeMenu(newPizza);
                    newPizza       = PizzaCrustMenu(newPizza);
                    newPizza       = PizzaToppingsMenu(newPizza, 2);
                    pizzaAddedFlag = CurrentPizzaOrder.AddPizzaToOrder(newPizza);
                    break;

                case 2:
                    IPizza customPizza = new PlainPizza();
                    customPizza    = PizzaSizeMenu(customPizza);
                    customPizza    = PizzaCrustMenu(customPizza);
                    customPizza    = PizzaToppingsMenu(customPizza, 1);
                    pizzaAddedFlag = CurrentPizzaOrder.AddPizzaToOrder(customPizza);
                    break;
                }
                if (pizzaAddedFlag)
                {
                    System.Console.WriteLine($"Pizza Added. Your order has: {CurrentPizzaOrder.GetTotalPizzaCount()} pizza(s)");
                    System.Console.WriteLine("Do you want to add more pizzas?");
                    System.Console.WriteLine("1- Yes 2- No");
                    System.Console.Write("Add Pizza Choice: ");
                    int addPizzaChoice = Convert.ToInt32(Console.ReadLine());
                    addMorePizzas = (addPizzaChoice == 1)? true : false;
                }
                else
                {
                    System.Console.WriteLine("Pizza Count/Total Order Cost Limit Reached!!!");
                    addMorePizzas = false;
                }
            }
        }
Example #3
0
        public IActionResult AddCustomPizza(string pizzaSizeCode,
                                            string pizzaCrustCode, List <string> pizzaToppingCodes)
        {
            byte [] orderArr;
            HttpContext.Session.TryGetValue("newOrder", out orderArr);
            PizzaOrder curOrder = PizzaOrder.ByteArrayToObject(orderArr);

            IPizza newPizza = new PlainPizza();

            newPizza = new PizzaSizeDecorator(newPizza, PizzaSizeDataRetriever
                                              .GetInstance().PizzaSizeList[Convert.ToInt32(pizzaSizeCode)]);
            newPizza = new PizzaCrustDecorator(newPizza, PizzaCrustDataRetriever
                                               .GetInstance().PizzaCrustList[Convert.ToInt32(pizzaCrustCode)]);

            foreach (var item in pizzaToppingCodes)
            {
                newPizza = new PizzaToppingDecorator(newPizza, PizzaToppingsDataRetriever
                                                     .GetInstance().PizzaToppingsList[Convert.ToInt32(item)]);
            }

            bool pizzaAdded = curOrder.AddPizzaToOrder(newPizza);

            HttpContext.Session.Set("newOrder", curOrder.ObjectToByteArray());

            if (pizzaAdded)
            {
                ViewData["msg"] = $"Pizza Added. Your order has: {curOrder.GetTotalPizzaCount()} pizza(s)";
            }
            else
            {
                ViewData["msg"] = "Pizza Count/Total Order Cost Limit Reached!!!";
            }

            ViewData["orderCount"] = curOrder.GetTotalPizzaCount();
            return(View("PizzaSelectionPage"));
        }
 public void GivenGetTotalPizzaCount()
 {
     _wholPizza = _pizza.GetTotalPizzaCount();
 }