Beispiel #1
0
        public ActionResult Login(OrderDisplay model)
        {
            var userList = Repo.GetUsers();

            OrderDisplay order = new OrderDisplay();

            order.FirstName = model.FirstName;
            order.LastName  = model.LastName;
            bool exists = false;

            foreach (var user in userList)
            {
                if (user.FirstName == model.FirstName && user.LastName == model.LastName)
                {
                    order.UserID        = user.UserID;
                    order.StoreLocation = user.StoreLocation;
                    order.OrderPref     = user.OrderPref;
                    exists = true;
                    break;
                }
            }
            if (exists == false)
            {
                Lib.EndUser user = new Lib.EndUser()
                {
                    FirstName = order.FirstName,
                    LastName  = order.LastName
                };
                Repo.AddUser(user);
                Repo.Save();
            }

            return(View("PlaceOrder", order));
        }
Beispiel #2
0
 public static Data.Users Map(EndUser user) => new Data.Users
 {
     UserId    = user.UserID,
     FirstName = user.FirstName,
     LastName  = user.LastName,
     StorePref = user.StoreLocation,
     OrderPref = user.OrderPref
 };
Beispiel #3
0
        public ActionResult PlaceOrder(OrderDisplay model)
        {
            var orderList = Repo.GetOrders();

            Lib.EndUser user = Repo.GetUserById(Repo.GetUserID(model.FirstName, model.LastName));

            Lib.Order order = new Lib.Order();
            order.UserID    = Repo.GetUserID(model.FirstName, model.LastName);
            order.StoreID   = model.StoreLocation;
            order.OrderTime = DateTime.Now;
            model.OrderTime = DateTime.Now;

            Lib.Pizza pizza = new Lib.Pizza();
            pizza.Size      = model.Size;
            pizza.Crust     = model.Crust;
            pizza.Sauce     = model.Sauce;
            pizza.Bacon     = model.Bacon;
            pizza.Pepperoni = model.Pepperoni;
            pizza.Sausage   = model.Sausage;
            pizza.Chicken   = model.Chicken;
            pizza.Onions    = model.Onions;
            pizza.Olives    = model.Olives;

            pizza.Price = pizza.CalculatePrice(pizza);
            order.Price = pizza.Price * model.PizzaCount;
            Repo.AddOrder(order);
            Repo.Save();
            pizza.OrderID = Repo.GetOrderID(order.UserID);
            Repo.AddPizza(pizza);
            Repo.Save();

            user.StoreLocation = model.StoreLocation;
            user.OrderPref     = model.PizzaID;
            Repo.UpdateUser(user);
            Repo.Save();
            model.Price = order.Price;
            Lib.Location store = Repo.GetStoreByID(order.StoreID);
            for (int i = 0; i < model.PizzaCount; i++)
            {
                if (pizza.Pepperoni)
                {
                    store.Pepperoni--;
                }
                if (pizza.Chicken)
                {
                    store.Chicken--;
                }
                if (pizza.Sausage)
                {
                    store.Sausage--;
                }
                if (pizza.Bacon)
                {
                    store.Bacon--;
                }
                if (pizza.Olives)
                {
                    store.Olives--;
                }
                if (pizza.Onions)
                {
                    store.Onions--;
                }
                if (pizza.Sauce == "BBQ")
                {
                    store.BBQSauce--;
                }
                else if (pizza.Sauce == "Buffalo")
                {
                    store.BuffaloSauce--;
                }
                else if (pizza.Sauce == "Marinara")
                {
                    store.MarinaraSauce--;
                }
                store.Dough--;
                store.Cheese--;
            }
            Repo.UpdateLocation(store);
            Repo.Save();

            return(View("OrderPlaced", model));
        }