コード例 #1
0
        public IActionResult Submit()
        {
            using (var transaction = _db.Database.BeginTransaction()){
                _db.Orders.Add(new Order()
                {
                    OrderCreated = UsersOrder.Storage().OrderCreated,
                    LocationId   = UsersOrder.Storage().Location.Id,
                    UserId       = CurrentUser.Storage().Id
                });

                _db.SaveChanges();
                var fetchOrderId = _db.Orders.Single(o => o.OrderCreated == UsersOrder.Storage().OrderCreated).Id;
                foreach (var PizzaObject in UsersOrder.Storage().Pizzas)
                {
                    _db.Pizzas.Add(new Pizza()
                    {
                        CrustId     = PizzaObject.Crust.Id,
                        SizeId      = PizzaObject.Size.Id,
                        Cost        = PizzaObject.Cost,
                        Description = PizzaObject.Description,
                        OrderId     = fetchOrderId
                    });
                }
                _db.SaveChanges();
                transaction.Commit();
            }
            CurrentUser.Storage().UserAbleToOrder = false;
            UsersOrder.DeleteStorage();
            //remove order infomation
            return(RedirectToAction("Receipt", "Order"));
        }
コード例 #2
0
        public IActionResult AddPizzaToOrder(User a)
        {
            //we have the sizeid and crustid and a list of topping id
            //which the user selected

            //If the user reach this part that mean that
            //user can make an order
            if (UsersOrder.IsEmpty())
            {
                UsersOrder.Storage().Location = _db.Locations.Single(l => l.Id == CurrentUser.Storage().SelectedLocation);
                // _order.Location.PhoneNumber = _db.Locations.Single(l => l.Id == CurrentUser.Storage().SelectedLocation).PhoneNumber;
                // _order.Location.Address = _db.Locations.Single(l => l.Id == a.SelectedLocation).Address;
                UsersOrder.Storage().OrderCreated = DateTime.Now;
                UsersOrder.Storage().User         = CurrentUser.Storage();

                // _order.Pizzas =  new List<Pizza>();

                //place the first pizza in order
                // AddPizzaToUsersOrder(ref a);
            }
            // else{
            // AddPizzaToUsersOrder(ref a);
            // }
            //Check for max toppings
            if (!CheckSelections(a))
            {
                return(RedirectToAction("Index", "Order"));
            }
            AddPizzaToUsersOrder(a);
            CurrentUser.Storage().Messages.MessageType = "AddedToOrder";
            CurrentUser.Storage().Messages.MessageToUser = $"Added a {UsersOrder.Storage().Pizzas.Last().Size.Name} and {UsersOrder.Storage().Pizzas.Last().Crust.Name} pizza to your order!";
            return(RedirectToAction("Index", "Order"));
        }
コード例 #3
0
 public IActionResult Cart()
 {
     if (CurrentUser.Storage().Messages != null)
     {
         CurrentUser.Storage().Messages.MessageType = "";
     }
     //if the user is wants to re-access the cart after a order he will be
     //sent back to the main index
     if (!CurrentUser.Storage().UserAbleToOrder)
     {
         return(RedirectToAction("Index", "Main"));
     }
     return(View(UsersOrder.Storage()));
 }
コード例 #4
0
        private void AddPizzaToUsersOrder(User a)
        {
            var newPizzaToPlace = new Pizza();

            newPizzaToPlace.Crust = _db.Crusts.Single(c => c.Id == a.SelectedCrust);
            newPizzaToPlace.Cost += newPizzaToPlace.Crust.Price;

            newPizzaToPlace.Size  = _db.Sizes.Single(s => s.Id == a.SelectedSize);
            newPizzaToPlace.Cost += newPizzaToPlace.Size.Price;

            newPizzaToPlace.Toppings    = new List <Topping>();
            newPizzaToPlace.Description = "";

            foreach (var selectedToppingId in a.SelectedToppings)
            {
                var fetchTopping = _db.Toppings.Single(t => t.Id == selectedToppingId);
                newPizzaToPlace.Description += fetchTopping.Name + " ";

                newPizzaToPlace.Toppings.Add(fetchTopping);
                newPizzaToPlace.Cost += fetchTopping.Price;
            }
            UsersOrder.Storage().Pizzas.Add(newPizzaToPlace);
        }