예제 #1
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);
            }
        }
예제 #2
0
        public static bool SetUser(pdm.User user)
        {
            //var address = _db.Address.First(a => a.Street == user.Address.Street);
            var dataUser = new User()
            {
                Name = user.Name
                       //,password if you have it
            };

            _db.User.Add(dataUser);

            return(_db.SaveChanges() == 1);

            //if (address == null)
            //{
            //    dataUser.Address = new Address()
            //    {
            //        City = user.Address.City,
            //        State = user.Address.State,
            //        Street = user.Address.Street
            //    };
            //} else
            //{
            //    dataUser.AddressId = address.AddressId;
            //}

            //_db.User.Add(dataUser);

            //return address == null ? _db.SaveChanges() == 2 : _db.SaveChanges() == 1;
        }
        public void Create(domain.User user)
        {
            var newUser = new User();

            newUser.Name = user.Name;

            foreach (var o in user.Orders) // extract orders to store
            {
                var order = new Order()
                {
                    DateTime = o.TimeOrdered, User = newUser
                };
                var userOrders = new UserOrders()
                {
                    Order = order, User = newUser
                };
                foreach (var p in o.Pizzas)
                {
                    var pizza = GetPizza(p);
                    order.OrderPizza.Add(new OrderPizza()
                    {
                        Order = order, Pizza = pizza
                    });
                }
                newUser.Order.Add(order);
                newUser.UserOrders.Add(userOrders);
            }
            _db.User.Add(newUser);
            System.Console.WriteLine("Added Successfully!");
            _db.SaveChanges();
        }
예제 #4
0
        public IActionResult login(LocationUser newuser)
        {
            var newUser = OrderViewModel.GetUserByName(newuser.Name);

            if (newUser == null)
            {
                if (newuser.password == newuser.secondary)
                {
                    var domuser = new dom.User()
                    {
                        name = newuser.Name, password = newuser.password
                    };
                    UserHelper.SetUser(domuser);
                    ViewData["name"] = newuser.Name;
                    return(View("Welcome"));
                }
                else
                {
                    ViewData["ErrorMessage"] = "Passwords don't match";
                    return(View("SignUp"));
                }
            }

            ViewData["name"] = newuser.Name;
            return(View("userexists"));
        }
예제 #5
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);
            }
        }
예제 #6
0
        //Inventory checking has been scrapped

        public static List <dom.User> GetUsersByLocation(Location dl)
        {
            var _db      = new PizzaStoreDbContext();
            var userlist = new List <dom.User>();

            var DesiredLUPairs = _db.LocationUser.Where(lu => lu.LocationId == dl.LocationId).ToList();

            foreach (var item in DesiredLUPairs)
            {
                if (item.Active == true)
                {
                    var myuser  = _db.User.Where(u => u.UserId == item.UserId).FirstOrDefault();
                    var domuser = new dom.User()
                    {
                        Id           = myuser.UserId,
                        name         = myuser.Name,
                        password     = myuser.Password,
                        ModifiedDate = myuser.ModifiedDate
                    };
                    userlist.Add(domuser);
                }
            }

            return(userlist);
        }
예제 #7
0
        public void ViewOrdersByStore(domain.Store store, domain.User user)
        {
            System.Console.WriteLine($"Viewing orders submitted by {user.Name} to {store.Name}\n");
            var orders = _db.Orders.Where(
                o => o.StoreSubmitted.Name == store.Name &&
                o.UserSubmitted.Name == user.Name
                ).ToList();

            foreach (var order in orders)
            {
                System.Console.WriteLine($"{order.PurchaseDate.ToString("G")} ----- Order Total: {order.Price.ToString("C2")}");
                var PizzaList = _db.Pizza
                                .Where(p => p.OrderId == order.OrderId)
                                .Include(p => p.Size)
                                .Include(p => p.Crust)
                                .Include(p => p.PizzaTopping)
                                .ThenInclude(p => p.Topping)
                                .ToList();
                foreach (var pizza in PizzaList)
                {
                    System.Console.WriteLine($"    {pizza.Name}, {pizza.Size.Name}, {pizza.Crust.Name} ----- {pizza.Price.ToString("C2")}");
                    System.Console.WriteLine($"    Toppings: {string.Join(", ", pizza.PizzaTopping.Select(t => t.Topping.Name))}");
                    System.Console.WriteLine();
                }
            }
        }
예제 #8
0
        public void Create(domain.User user)
        {
            var newUser = new User();

            _db.User.Add(newUser);
            newUser.Name = user.Name;
            _db.SaveChanges();
        }
        public void Create(domain.User User)
        {
            var newUser = new Users();

            newUser.FirstName = User.firstname;
            newUser.LastName  = User.lastname;

            _db.Users.Add(newUser);
            _db.SaveChanges();
        }
예제 #10
0
        public void CreateUser(domain.User user)
        {
            var newUser = new Users()
            {
                Name  = user.Name,
                Pword = user.Password,
            };

            _db.Users.Add(newUser);
            _db.SaveChanges();
        }
예제 #11
0
        public static void GetOrders(dom.User thisuser)
        {
            var datauser  = _db.User.Where(u => u.UserId == thisuser.Id).FirstOrDefault();
            var orderlist = UserHelper.GetOrdersByUser(datauser);

            DisplayOrderList(orderlist);
            Console.WriteLine("\n Press enter to move forward");
            var holder = Console.ReadLine();

            UserMenu(thisuser);
        }
예제 #12
0
        public static pdm.User GetUser(pdm.User user)
        {
            var du = _db.User.Where(u => u.Name == user.Name).FirstOrDefault();

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

            return(user);
        }
예제 #13
0
        //public static List<pdm.Order> GetOrderByLocation(pdm.Location location)
        //{
        //    var dataLocation = _db.Location.Where(l => l.LocationId == location.LocationId).FirstOrDefault();

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

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

        public static List <pdm.Order> GetOrderByUser(pdm.User user)
        {
            var dataUser = _db.User.Where(u => u.UserId == user.UserId).FirstOrDefault();

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

            return(GetOrders(dataUser.Order));
        }
예제 #14
0
        public bool SetUser(d.User u)
        {
            var du = new User();

            du.Name     = "Peter";
            du.LastTime = DateTime.Now;
            //du.UserId = 5;
            //du.DateModified = DateTime.Now.AddHours(6);
            //du.Active = true;

            _db.User.Add(du);
            return(_db.SaveChanges() == 1);
        }
예제 #15
0
        public static int SetUser(dom.User u)
        {
            var _db      = new PizzaStoreDbContext();
            var datauser = new User()
            {
                ModifiedDate = DateTime.Now
                , Name       = u.name
                , Password   = u.password
            };

            _db.User.Add(datauser);
            return(_db.SaveChanges());
        }
예제 #16
0
        static void UserSearch(domain.User user)
        {
            System.Console.WriteLine("Enter Name");
            string name = Console.ReadLine();

            //System.Console.WriteLine("Enter Username");
            //string uname = Console.ReadLine();
            //get uname from db and match
            System.Console.WriteLine("Enter Password");
            string pword = Console.ReadLine();

            user.Name = name;
            //user.Username = uname;
            user.Password = pword;
        }
예제 #17
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();
        }
예제 #18
0
        public static void UserMenu(dom.User thisUser)
        {
            Console.WriteLine("Please pick an option");
            Console.WriteLine("1: Create Order");
            Console.WriteLine("2: Read History");
            Console.WriteLine("3: Exit");

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

            if (Int32.TryParse(selection, out intSelection) == false)
            {
                Console.WriteLine("Invalid option, please try again");
                UserMenu(thisUser);
            }
            else
            {
                switch (intSelection)
                {
                case 1:
                    LocationMenu(thisUser);
                    break;

                case 2:
                    GetOrders(thisUser);
                    break;

                case 3:
                    Console.WriteLine("Farewell!");
                    TopMenu();
                    break;

                default:
                    Console.WriteLine("Invalid option, please try again");
                    UserMenu(thisUser);
                    break;
                }
            }
        }
예제 #19
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);
        }
예제 #20
0
        //private static PizzaStoreDbContext _db = new PizzaStoreDbContext();

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

            foreach (var l in _db.User.ToList())
            {
                if (l.Active == true)
                {
                    var domU = new dom.User()
                    {
                        name         = l.Name,
                        password     = l.Password,
                        Id           = l.UserId,
                        ModifiedDate = l.ModifiedDate
                    };


                    ls.Add(domU);
                }
            }

            return(ls);
        }
예제 #21
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);
        }
예제 #22
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
            }
        }