Пример #1
0
        static void Welcome()
        {
            System.Console.WriteLine("Welcome to the Pizza Shop");
            System.Console.WriteLine("Best Pizza in the 462");
            //select either user or store story
            try
            {
                //ask to create or login
                var pr = new PizzaRepo();

                domain.Store store = StoreSelect();
                pr.CreateStore(store);

                domain.User user = new domain.User()
                {
                    Orders = store.Orders
                };
                UserSearch(user);
                pr.CreateUser(user);

                domain.Order order = store.CreateOrder();
                pr.CreateOrder(order);

                Menu(order, user, store, pr);     //set orders equiv for this run of program
            }
            catch (Exception ex)
            {
                System.Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        //private static PizzaStoreDbContext _db = new PizzaStoreDbContext();



        public static List <dom.Order> GetOrders()
        {
            var _db = new PizzaStoreDbContext();
            var ls  = new List <dom.Order>();

            foreach (var l in _db.Order.ToList())
            {
                if (l.Active == true)
                {
                    var newOrder = new dom.Order()
                    {
                        Id = l.OrderId
                        ,
                        StoreID = (byte)l.StoreId
                        ,
                        TimeStamp = l.TimeStamp
                        ,
                        UserID = (short)l.UserId
                        ,
                        Voidable = (bool)l.Voidable
                    };
                    ls.Add(newOrder);
                }
            }

            return(ls);
        }
        public void CreateOrderDb(domain.Order order)
        {
            var newOrder = new Orders();

            _db.Orders.Add(newOrder);
            _db.SaveChanges();
        }
Пример #4
0
        public static int SetOrder(dom.Order r)
        {
            var _db    = new PizzaStoreDbContext();
            var loc    = _db.Location.Where(l => l.LocationId == r.StoreID).FirstOrDefault();
            var myuser = _db.User.Where(u => u.UserId == r.UserID).FirstOrDefault();

            if (loc == null || myuser == null)
            {
                return(0);
            }
            else
            {
                var dataorder = new Order()
                {
                    Cost        = (decimal)r.Cost()
                    , StoreId   = r.StoreID
                    , Voidable  = r.Voidable
                    , TimeStamp = DateTime.Now
                    , UserId    = r.UserID
                };

                var locuserpair = new LocationUser()
                {
                    LocationId = loc.LocationId,
                    UserId     = myuser.UserId
                };

                _db.LocationUser.Add(locuserpair);
                _db.Order.Add(dataorder);
                return(_db.SaveChanges());
            }
        }
Пример #5
0
        public static List <dom.Order> GetOrderByUser(User user)
        {
            var _db      = new PizzaStoreDbContext();
            var dataUser = _db.User.Where(u => u.UserId == user.UserId).FirstOrDefault();

            if (dataUser != null)
            {
                var orders = new List <dom.Order>();

                foreach (var item in dataUser.Order.ToList())
                {
                    if (item.Active == true)
                    {
                        var domOrder = new dom.Order()
                        {
                            Id        = item.OrderId,
                            TimeStamp = item.TimeStamp,
                            Voidable  = (bool)item.Voidable,
                            UserID    = (short)item.UserId,
                            StoreID   = (byte)item.StoreId
                        };
                        orders.Add(domOrder);
                    }
                }
                return(orders);
            }

            return(null);
        }
Пример #6
0
        public static List <dom.Order> GetOrderByLocation(Location Loc)
        {
            var _db        = new PizzaStoreDbContext();
            var dataorders = _db.Order.Where(o => o.StoreId == Loc.LocationId).ToList();

            var orderlist = new List <dom.Order>();

            foreach (var item in dataorders)
            {
                if (item.Active == true)
                {
                    var domorder = new dom.Order()
                    {
                        Id        = item.OrderId,
                        TimeStamp = item.TimeStamp,
                        StoreID   = (byte)item.StoreId,
                        Voidable  = (bool)item.Voidable,
                        UserID    = (short)item.UserId,
                        Store     = LocationHelper.GetLocationByOrder(item),
                        PizzaList = GetPizzasByOrder(item),
                        finalCost = GetCostByOrder(item)
                    };
                    orderlist.Add(domorder);
                }
            }

            return(orderlist);
        }
Пример #7
0
        public static void LocationMenu(dom.User myuser)
        {
            Console.WriteLine("Please pick from any of our locations below");
            var locationList = _db.Location.ToList();

            foreach (var l in locationList)
            {
                Console.Write($"{l.LocationId} ");
            }
            Console.Write("\n");
            var stringSelection = Console.ReadLine();
            int selection;

            if (false == Int32.TryParse(stringSelection, out selection))
            {
                Console.WriteLine("Invalid location");
                LocationMenu(myuser);
            }
            else
            {
                var newOrder = new dom.Order()
                {
                    UserID    = (short)myuser.Id,
                    StoreID   = (byte)selection,
                    TimeStamp = DateTime.Now
                };

                newOrder.PizzaList.Add(new dom.Pizza());

                OrderMenu(newOrder);
            }
        }
Пример #8
0
        public static List <dom.Order> GetOrdersByLocation(Location dl)
        {
            var _db    = new PizzaStoreDbContext();
            var orders = new List <dom.Order>();

            var desiredOrders = _db.Order.Where(r => r.StoreId == dl.LocationId).ToList();

            foreach (var item in desiredOrders)
            {
                if (item.Active == true)
                {
                    var newOrder = new dom.Order()
                    {
                        Id        = item.OrderId,
                        StoreID   = (byte)item.StoreId,
                        TimeStamp = item.TimeStamp,
                        UserID    = (short)item.UserId,
                        Voidable  = (bool)item.Voidable
                    };
                    orders.Add(newOrder);
                }
            }

            return(orders);
        }
Пример #9
0
        public static int SetDefaultOrder(int StoreId, string name)
        {
            var domUser  = GetUserByName(name);
            var domOrder = new dom.Order()
            {
                UserID  = (short)domUser.Id,
                StoreID = (byte)StoreId
            };

            domOrder.PizzaList.Add(new dom.Pizza());

            OrderHelper.SetOrder(domOrder);
            var orderlist = UserHelper.GetOrdersByUser(new dat.User()
            {
                UserId = (short)domUser.Id
            });
            var lastOrder = orderlist[orderlist.Count - 1];

            foreach (var item in domOrder.PizzaList)
            {
                item.OrderId = lastOrder.Id;
                PizzaHelper.PizzaSetter(item);
            }

            return(lastOrder.Id);
        }
Пример #10
0
        static void DisplayCart(domain.Order cart)
        {
            int cnt = 1;

            foreach (var pizza in cart.Pizzas)
            {
                System.Console.WriteLine("Pizza " + cnt + ": " + pizza.ToString());
                cnt += 1;
            }
        }
Пример #11
0
        public void CreateOrder(domain.Order order)
        {
            var newOrder = new Orders()
            {
                OrderDate = order.DateOrdered,
            };

            _db.Orders.Add(newOrder);
            _db.SaveChanges();
        }
        public List <domain.Order> ReadPizzaOrdersByUser(string username)
        {
            // var domainUserPizzaList = new List<domain.PizzaModel.Pizza>();
            var domainUserOrdersList = new List <domain.Order>();

            var query         = _db.Order.Include(u => u.User).Where(u => u.User.Name == username);
            var extendedQuery = query.Include(o => o.OrderPizza).ThenInclude(p => p.Pizza).ThenInclude(c => c.Crust)
                                .Include(o => o.OrderPizza).ThenInclude(p => p.Pizza).ThenInclude(s => s.Size)
                                .Include(o => o.OrderPizza).ThenInclude(p => p.Pizza).ThenInclude(pt => pt.PizzaTopping).ThenInclude(t => t.Topping);

            foreach (var q in extendedQuery)
            {
                var order = new domain.Order()
                {
                    TimeOrdered = q.DateTime
                };
                // System.Console.WriteLine(q.User.Name);
                // System.Console.WriteLine(q.DateTime);
                foreach (var ran in q.OrderPizza)
                {
                    var toppings = new List <domain.PizzaModel.Topping>();
                    foreach (var pt in ran.Pizza.PizzaTopping)
                    {
                        var topping = new domain.PizzaModel.Topping()
                        {
                            Name = pt.Topping.Name, Price = (double)pt.Topping.Price
                        };
                        toppings.Add(topping);
                    }
                    // System.Console.WriteLine(ran.Pizza.Name);
                    order.Pizzas.Add(new domain.PizzaModel.Pizza()
                    {
                        Name = new domain.PizzaModel.Name()
                        {
                            PizzaName = ran.Pizza.Name
                        },
                        Crust = new domain.PizzaModel.Crust()
                        {
                            PizzaCrust = ran.Pizza.Crust.Name, CrustPrice = (double)ran.Pizza.Crust.Price
                        },
                        Size = new domain.PizzaModel.Size()
                        {
                            PizzaSize = ran.Pizza.Size.Name, SizePrice = (double)ran.Pizza.Size.Price
                        },
                        PizzaPrice = ran.Pizza.Price,
                        Toppings   = toppings
                    });
                }
                domainUserOrdersList.Add(order);
            }
            return(domainUserOrdersList);
        }
Пример #13
0
        //get pizzas
        //public static List<pdm.Pizza> GetPizzaByLocation(pdm.Location location)
        //{
        //    var dataLocation = _db.Location.Where(l => l.LocationId == location.LocationId).FirstOrDefault();

        //    if (dataLocation == null)
        //    {
        //        return null;
        //    }

        //    return GetPizzas(dataLocation.Order);
        //}

        public static List <pdm.Pizza> GetPizzaByOrder(pdm.Order order)
        {
            var dataOrder = _db.Order.Where(o => o.OrderId == order.OrderId).FirstOrDefault();

            if (dataOrder == null)
            {
                return(null);
            }

            return(GetPizzas(new List <Order>()
            {
                dataOrder
            }));
        }
Пример #14
0
        public static bool SetOrder(pdm.Order order)
        {
            var dataOrder = new Order()
            {
                LocationId  = order.LocationId,
                UserId      = order.UserId,
                Total       = 10,
                DateOrdered = DateTime.Now,
                Active      = true
            };

            _db.Order.Add(dataOrder);

            return(_db.SaveChanges() == 1);
        }
Пример #15
0
        public void CreateOrder(domain.Order order, domain.User user, domain.Store store)
        {
            var newOrder = new Orders();

            newOrder.Price          = order.CalculatePrice();
            newOrder.UserSubmitted  = _db.Users.FirstOrDefault(u => u.Name == user.Name);
            newOrder.StoreSubmitted = _db.Store.FirstOrDefault(s => s.Name == store.Name);

            foreach (var pizza in order.Pizzas)
            {
                newOrder.Pizza.Add(ConvertToDbPizza(pizza));
            }

            _db.Orders.Add(newOrder);
            _db.SaveChanges();
        }
Пример #16
0
 public static void DisplayOrder(dom.Order o)
 {
     Console.WriteLine("\n\n\n\n\n");
     Console.WriteLine($"Order #{o.Id}; DateTime={o.TimeStamp} ;Store #{o.StoreID}; Total=${o.Cost()}");
     foreach (var p in o.PizzaList)
     {
         var crustname = PizzaHelper.GetCrustNameByPizza(p);
         Console.WriteLine($"Pizza#{p.Id}  Size={p.crustSize}in {crustname} crust");
         Console.Write("Toppings:");
         foreach (var ingred in p.Toppings)
         {
             Console.Write($"{ingred} ");
         }
         Console.Write($"; ${p.price}\n");
     }
 }
Пример #17
0
        public static void SubmitOrder(dom.Order o)
        {
            Console.WriteLine("Finalizing Order:");
            DisplayOrder(o);

            var osets       = OrderHelper.SetOrder(o);
            var Totalorders = _db.Order.ToList();
            var lastOrder   = Totalorders[Totalorders.Count - 1];

            foreach (var item in o.PizzaList)
            {
                item.OrderId = lastOrder.OrderId;
                var pSets = PizzaHelper.PizzaSetter(item);
            }
            Console.WriteLine("Thank you for your business!");

            var userlist = GetUsers();

            UserMenu(userlist.FirstOrDefault(u => u.Id == o.UserID));
        }
Пример #18
0
        public void CreateOrderDb(domain.Order order)
        {
            var newOrder = new Orders();

            newOrder.Store = new Stores();
            newOrder.User  = new Users();

            newOrder.Store.StoreName = order.Store;
            newOrder.User.UserName   = order.User;

            foreach (var p in order.Pizzas)
            {
                var newPizza = new Pizza();
                newPizza.PizzaName  = p.Name;
                newPizza.Qty        = p.Qty;
                newPizza.PizzaPrice = p.Price;
                newOrder.Pizza.Add(newPizza);
            }

            _db.Orders.Add(newOrder);
            _db.SaveChanges();
        }
Пример #19
0
        public static void CrustMenu(dom.Order o, int selectedPizza)
        {
            var target    = o.PizzaList[selectedPizza - 1];
            var crustlist = _db.Crust.ToList();

            Console.WriteLine("Select Crust Type");
            var i = 1;

            foreach (var item in crustlist)
            {
                Console.WriteLine($"{i}: {item.Name}");
                i++;
            }
            var selection = Console.ReadLine();
            int trueSelect;

            if (false == Int32.TryParse(selection, out trueSelect))
            {
                Console.WriteLine("Incorrect Selection");
                CrustMenu(o, selectedPizza);
            }
            else
            {
                if (trueSelect > 0 && trueSelect <= crustlist.Count())
                {
                    target.CrustId     = crustlist[trueSelect - 1].CrustId;
                    target.CrustFactor = (double)crustlist[trueSelect - 1].CrustFactor;
                    target.price       = target.CalculateCost();
                    PizzaEdit(o, selectedPizza);
                }
                else
                {
                    Console.WriteLine("Incorrect Selection");
                    CrustMenu(o, selectedPizza);
                }
            }
        }
Пример #20
0
        public void CreateOrderCustomerPizzaRelationT()
        {
            var sut   = new PizzaStore.Storing.Repositories.OrderRepository();
            var user  = new model.User("TestUser", "TestUser");
            var order = new model.Order();

            order.Pizzas = new List <model.Pizza>();
            order.CreatePizza(
                "Cheese",
                new List <Domain.Models.Topping>()
            {
                new Domain.Models.Topping("Marinara Sauce", 0),
                new Domain.Models.Topping("Regular Cheese", 0)
            },
                new Domain.Models.Crust("Plain", 0),
                new Domain.Models.Size("Large", 4),
                6);


            user.Orders.Add(order);
            //action
            bool passed = false;

            try
            {
                sut.CreateOrderCustomerPizzaRelation(user);
                passed = true;
            }
            catch
            {
                passed = false;
            }

            //assert

            Assert.True(passed);
        }
Пример #21
0
        public static void OrderMenu(dom.Order current)
        {
            DisplayOrder(current);
            var i = 1;

            foreach (var p in current.PizzaList)
            {
                var    num     = i.ToString();
                var    lastdig = num[num.Length - 1];
                string suffix;

                switch (lastdig)
                {
                case '1':
                    suffix = "st";
                    break;

                case '2':
                    suffix = "nd";
                    break;

                case '3':
                    suffix = "rd";
                    break;

                default:
                    suffix = "th";
                    break;
                }
                Console.WriteLine($"{i}: edit {i}{suffix} pizza");
                i++;
            }
            Console.WriteLine($"{i}: Create new pizza");
            i += 1;
            Console.WriteLine($"{i}: Submit Order");
            i += 1;
            Console.WriteLine($"{i}: Cancel Order");

            var stringSelection = Console.ReadLine();
            int selection;

            if (false == Int32.TryParse(stringSelection, out selection))
            {
                Console.WriteLine("Invalid choice");
                OrderMenu(current);
            }
            else
            {
                if (selection < 0)
                {
                    Console.WriteLine("Invalid choice");
                    OrderMenu(current);
                }
                else if (selection <= current.PizzaList.Count)
                {
                    PizzaEdit(current, selection);
                }
                else if (selection == (current.PizzaList.Count + 1))
                {
                    current.PizzaList.Add(new dom.Pizza());
                    OrderMenu(current);
                }
                else if (selection == (current.PizzaList.Count + 2))
                {
                    SubmitOrder(current);
                }
                else if (selection == (current.PizzaList.Count + 3))
                {
                    var userlist = GetUsers();
                    var myuser   = userlist.FirstOrDefault(u => u.Id == current.UserID);
                    UserMenu(myuser);
                }
                else
                {
                    Console.WriteLine("Invalid choice");
                    OrderMenu(current);
                }
            }
        }
Пример #22
0
        public static void PizzaEdit(dom.Order o, int selectedPizza)
        {
            var target = o.PizzaList[selectedPizza - 1];

            DisplayPizza(target);

            var IngredientObjects = _db.Ingredient.ToList();
            var Ingredients       = new List <String>();

            foreach (var ingred in IngredientObjects)
            {
                Ingredients.Add(ingred.Name);
                target.price = target.CalculateCost();
            }

            if (target.Toppings.Count >= 5)
            {
                Console.WriteLine("Topping limit reached.");
                Console.WriteLine("1: Change size");
                Console.WriteLine("2: Change crust type");
                Console.WriteLine("3: Return to OrderMenu");
                var s = Console.ReadLine();
                switch (s)
                {
                case "1":
                    Console.WriteLine("Insert new size (inches)");
                    var newS = Console.ReadLine();
                    int selection;
                    if (false == Int32.TryParse(newS, out selection))
                    {
                        Console.WriteLine("Invalid choice");
                    }
                    else
                    {
                        target.crustSize = selection; target.price = target.CalculateCost();
                    }
                    PizzaEdit(o, selectedPizza);
                    break;

                case "2":
                    CrustMenu(o, selectedPizza);
                    break;

                case "3":
                    OrderMenu(o);
                    break;

                default:
                    Console.WriteLine("Invalid choice");
                    OrderMenu(o);
                    break;
                }
                OrderMenu(o);
            }
            else
            {
                for (var i = 1; i < Ingredients.Count; i++)//First entry is crust. Let's skip that for now.
                {
                    Console.WriteLine($"{i}: Add {Ingredients[i]}");
                }
                Console.WriteLine($"{Ingredients.Count}: Change Pizza Size");
                Console.WriteLine($"{Ingredients.Count+1}: Change Crust Type");
                Console.WriteLine($"{Ingredients.Count + 2}: Return to OrderMenu");
                var stringSelection = Console.ReadLine();
                int selection;
                if (false == Int32.TryParse(stringSelection, out selection))
                {
                    Console.WriteLine("Invalid choice");
                    PizzaEdit(o, selectedPizza);
                }
                else
                {
                    if ((selection <= 0) || (selection > (Ingredients.Count + 2)))
                    {
                        Console.WriteLine("Invalid choice");
                        PizzaEdit(o, selectedPizza);
                    }
                    else if (selection == Ingredients.Count)
                    {
                        Console.WriteLine("Insert new size (inches)");
                        var newS = Console.ReadLine();
                        int sel;
                        if (false == Int32.TryParse(newS, out sel))
                        {
                            Console.WriteLine("Invalid choice");
                        }
                        else
                        {
                            target.crustSize = sel; target.price = target.CalculateCost();
                        }
                        PizzaEdit(o, selectedPizza);
                    }
                    else if (selection == (Ingredients.Count + 1))
                    {
                        CrustMenu(o, selectedPizza);
                    }
                    else if (selection == (Ingredients.Count + 2))
                    {
                        OrderMenu(o);
                    }
                    else
                    {
                        target.Toppings.Add(Ingredients[selection]); PizzaEdit(o, selectedPizza);
                    }
                }
            }
        }
Пример #23
0
        public void CreatePizza(domain.Pizza pizza, domain.Order order, domain.Store store, domain.User user)
        {
            var newPizza        = new Pizza();
            var newTopping      = new Topping();
            var newPizzaTopping = new PizzaTopping();

            //var newOPT = new OrdersPizzaTopping();
            //var newOrder = new Orders();
            //var newStore = new Store();
            //var newUser = new Users();
            //newPizza.Crust = _db.Crust.FirstOrDefault(Crust ==> Name = pizza.Crust.Name);

            newPizza.Crust = new Crust()
            {
                Name = pizza.Crust.Name
            };
            newPizza.Size = new Size()
            {
                Name = pizza.Size.Name
            };
            newPizza.Name = pizza.Name.PizzaName;
            _db.Pizza.Add(newPizza);    //git add equiv for db
            _db.SaveChanges();

            //newOrder.OrderDate = order.DateOrdered;//retrieve current order

            /*var orderNum = _db.Orders.Include(d => d.OrdersPizzaTopping)
             *   .Where(f => f.OrderDate == newOrder.OrderDate)
             *   .FirstOrDefault(); //should only be one order
             *
             * newStore.Name = store.Name;//retrieve current order
             * var storeNum = _db.Store.Include(d => d.OrdersPizzaTopping)
             *   .Where(f => f.Name == newStore.Name)
             *   .FirstOrDefault(); //should only be one order
             *
             * newUser.Name = user.Name;//retrieve current order
             * var userNum = _db.Users.Include(d => d.OrdersPizzaTopping)
             *   .Where(f => f.Name == newUser.Name)
             *   .FirstOrDefault(); //should only be one order
             */

            foreach (var item in pizza.Toppings)
            {
                newTopping = new Topping {
                    Name = item.Name
                };
                _db.Topping.Add(newTopping);
                _db.SaveChanges();    //add to topping table

                //newPizzaTopping.PizzaId = newPizza.PizzaId;
                //newPizzaTopping.ToppingId = newTopping.ToppingId;
                //_db.PizzaTopping.Add(newPizzaTopping);
                //_db.SaveChanges();//add to PizzaTopping table

                //newOPT.OrderId = orderNum.OrderId;
                //newOPT.StoreId = storeNum.StoreId;
                //newOPT.UserId = userNum.UserId;
                //newOPT.PizzaToppingId = newPizzaTopping.PizzaToppingId;
                //_db.OrdersPizzaTopping.Add(newOPT); //add to OPT table
                //_db.SaveChanges(); //git commit equiv for db
            }
        }
Пример #24
0
        static void Menu(domain.Order cart, domain.User u, domain.Store s, PizzaRepo pr)
        {
            var order = true;

            do
            {
                s.PrintMenu();

                int select;

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

                switch (select)
                {
                case 1:
                    pr.CreatePizza(cart.CreatePizza("Cheesy Pizza", "L", "NY Style", new List <string> {
                        "Cheese, Sauce"
                    }), cart, s, u);
                    System.Console.WriteLine("Added Cheese Pizza");
                    break;

                case 2:
                    pr.CreatePizza(cart.CreatePizza("Pepperoni Pizza", "L", "NY Style", new List <string> {
                        "Cheese, Sauce, Pepperoni"
                    }), cart, s, u);
                    System.Console.WriteLine("Added Pepperoni Pizza");
                    break;

                case 3:
                    pr.CreatePizza(cart.CreatePizza("Hawaiian Pizza", "L", "NY Style", new List <string> {
                        "Cheese, Sauce, Pineapple, Ham"
                    }), cart, s, u);
                    System.Console.WriteLine("Added Hawaiian Pizza");
                    break;

                case 4:
                    pr.CreatePizza(cart.CreatePizza("Meat Lovers Pizza", "L", "NY Style", new List <string> {
                        "Cheese, Sauce, Pepperoni, Sausage, Bacon"
                    }), cart, s, u);
                    System.Console.WriteLine("Added Meat Lovers Pizza");
                    break;

                case 5:
                    domain.Pizza custom = cart.CustomPizza();
                    pr.CreatePizza(custom, cart, s, u);
                    System.Console.WriteLine("Added Custom Pizza");
                    break;

                case 6:
                    DisplayCart(cart);
                    break;

                //case 7:
                //EditCart()
                // break;
                case 7:
                    System.Console.WriteLine("Exit Order");
                    order = false;
                    break;
                }
            } while (order);
        }
 public void Create(domain.Order order)
 {
 }