예제 #1
0
        public List <Orders> GetOrders(int mode = 0, params string[] search_param)
        {
            var orderList = ctx.Orders.Include("Store").Include("Customer").AsQueryable();

            using (var context = new Game_RealmContext())
            {
                switch (mode)
                {
                case 1:
                    orderList = orderList
                                .Where(o => o.Store.StoreName == search_param[0]);
                    break;

                case 2:
                    orderList = orderList
                                .Where(o => o.Customer.FirstName == search_param[0] && o.Customer.LastName == search_param[1]);
                    break;

                case 3:
                    orderList = orderList
                                .Where(o => o.CustomerId == Convert.ToInt32(search_param[0]));
                    break;

                default:
                    break;
                }
            }
            return(orderList
                   .Include("OrderItem")
                   .Include("OrderItem.P")
                   .Include("OrderItem.P.P")
                   .ToList());
        }
예제 #2
0
        public static void showLocation(Game_RealmContext ctx)
        {
            List <Locations> locations_list = ctx.Locations.ToList();

            foreach (var item in locations_list)
            {
                Console.WriteLine("GameRealm Name: " + item.StoreName + "\nPhone Number: " + item.Phone + "\nE-Mail: " + item.Email + "\nStreet: " + item.Street + "\nCity: " + item.City + "\nState: " + item.State + "\nZipCode: " + item.ZipCode + "\nStoreID: " + item.StoreId + "\n\n");
            }
        }
예제 #3
0
        public Locations LoadStoreByID(int storeID)
        {
            using Game_RealmContext context = new Game_RealmContext();

            var storeMatched = from store in context.Locations
                               where store.StoreId == storeID
                               select store;

            return(storeMatched.First());
        }
        public void gameInventory()
        {
            var          ctx         = new Game_RealmContext();
            List <Games> listOfGames = ctx.Games.ToList();

            foreach (var item in listOfGames)
            {
                Console.WriteLine("GameID: " + item.ProductId + "\nTitle: " + item.Title + "\nGenre: " + item.Genre + "\nRelease Date: " + item.Release + "\nPrice: " + "$" + item.Price + "\n\n");
            }
        }
예제 #5
0
 public void InitializeStore(Locations S_Stores, IDataStore store)
 {
     using Game_RealmContext context = new Game_RealmContext();
     store.StoreName = S_Stores.StoreName;
     store.Street    = S_Stores.Street;
     store.City      = S_Stores.City;
     store.State     = S_Stores.State;
     store.Zipcode   = S_Stores.ZipCode;
     store.StoreId   = S_Stores.StoreId;
 }
예제 #6
0
        public void Add(Library.Customer customer)
        {
            using Game_RealmContext ctx = new Game_RealmContext();
            var C_Customer = new Model.Customer();

            // add BusinessLogic Customer to DbCustomer
            C_Customer.FirstName = customer.firstName;
            C_Customer.LastName  = customer.lastName;
            C_Customer.Password  = customer.Password;
            C_Customer.UserName  = customer.Username;


            ctx.Add(C_Customer);
            ctx.SaveChanges();
        }
예제 #7
0
        public static void storeInventory(Game_RealmContext ctx)
        {
            var sInventory = from sales in ctx.Games
                             join products in ctx.Inventory on sales.Title equals products.Title
                             select(products);

            var prodList = ctx.Inventory.Include("GameRealm").ToList();


            List <Inventory> listOfGames = ctx.Inventory.ToList();

            foreach (var item in prodList)
            {
                Console.WriteLine($"GameRealm: {item.Store.StoreName}\tTitle: {item.Title}\tQuantity: {item.Quantity}\n");
            }
        }
예제 #8
0
        public void SaveOrder(Orders order, ICustomer customer, IDataStore store)
        {
            using Game_RealmContext context = new Game_RealmContext();
            var O_Orders = new Orders();

            // add BusinessLogic Order to DBOrders
            O_Orders.CustomerId = customer.CustomerId;
            O_Orders.StoreId    = store.StoreId;
            O_Orders.Checkout   = order.Checkout;

            O_Orders.Time = DateTime.Now; // local time


            context.Add(O_Orders);
            context.SaveChanges();
        }
예제 #9
0
        public void SaveStore(IDataStore store)
        {
            using Game_RealmContext context = new Game_RealmContext();
            var S_Stores = new Locations();

            // add BusinessLogic Store to DbStores
            S_Stores.StoreName = store.StoreName;
            S_Stores.Street    = store.Street;
            S_Stores.City      = store.City;
            S_Stores.State     = store.State;
            S_Stores.ZipCode   = store.Zipcode;


            context.Add(S_Stores);
            context.SaveChanges();
        }
예제 #10
0
        public IActionResult Create([Bind("LocationId,CustomerId,ProductID")] OrdersViewModel ordersV)
        {
            Game_RealmContext ctx = new Game_RealmContext();

            if (ModelState.IsValid)
            {
                string orderlinesController = "Orderlines";
                Orders newOrd = new Orders
                {
                    CustomerId = ordersV.CustomerId,
                    StoreId    = ordersV.LocationId,
                    Time       = DateTime.Now,
                    Checkout   = 0
                };



                _context.Add(newOrd);
                _context.SaveChanges();
                _context.Entry(newOrd).Reload();
                Orderline ords = new Orderline
                {
                    OrderId   = newOrd.OrderId,
                    ProductId = ordersV.ProductID,
                    Quantity  = 1,
                };

                _context.Orderline.Add(ords);
                _context.SaveChanges();
                _context.Entry(ords).Reload();
                return(RedirectToAction(nameof(Create), orderlinesController));
            }



            ViewData["CustomerId"] = new SelectList(_context.Customer, "CustomerId", "FirstName");
            ViewData["StoreId"]    = new SelectList(_context.Locations, "StoreId", "StoreName");
            ViewData["ProductID"]  = new SelectList(_context.Games, "ProductId", "Title");
            ViewData["Price"]      = new SelectList(_context.Games, "Price", "Price");
            return(RedirectToAction(nameof(Index)));
        }
예제 #11
0
        public static void customerSearch(Game_RealmContext ctx, Customer cust)
        {
            Console.WriteLine("Who would you like you like to search for? \n");
            Thread.Sleep(800);
            string userINput = Console.ReadLine();

            var custSearch = from sales in ctx.Customer
                             where sales.FirstName == userINput
                             select sales;
            /*var custOrderHistory = ctx.Orders.Include("Orders").ToList();*/

            var custName = ctx.Customer.FirstOrDefault(cid => cid.FirstName == userINput);

            if (custName != null)
            {
                foreach (var item in custSearch)
                {
                    Console.WriteLine("\n");
                    Console.WriteLine("\t\t\t\t\tCustomer Found!");
                    Console.WriteLine("\n");
                    Console.WriteLine($"First Name: {item.FirstName}\nLast Name: {item.LastName}\n\nUser Name:  {item.UserName}");
                    var orderHist = ctx.Orders.Where(order => order.CustomerId == item.CustomerId).Include("Orderline").ToList();

                    foreach (var item2 in orderHist)
                    {
                        foreach (var item3 in item2.Orderline)
                        {
                            Console.WriteLine($"OrderID: {item3.OrderId}\tProductID: {item3.ProductId}\tQuantity: {item3.Quantity}\tPurchase Date: {item3.Order.Time}");
                        }
                    }
                }
            }

            else
            {
                Console.WriteLine("\ninvalid Entry! or Customer not Found!\n\n");
                Thread.Sleep(1000);
                promptUser.promtUserMenu(ctx, cust);
            }
        }
 public static int SelectStore(Game_RealmContext ctx, int uInput)
 {
     while (true)
     {
         try
         {
             uInput = int.Parse(Console.ReadLine());
             if (ctx.Locations.Find(uInput) != null)
             {
                 break;
             }
             else
             {
                 Console.WriteLine("You Must Enter the correct Store ID: ");
             }
         }
         catch (Exception)
         {
             Console.WriteLine("incorrect input, enter valid location ID!");
         }
     }
     return(uInput);
 }
        public static void addCustomer(Game_RealmContext ctx)
        {
            Customer newCust = new Customer();



            Console.WriteLine("Please Enter your first name: ");
            newCust.FirstName = Console.ReadLine();
            Console.WriteLine("Please enter your Last Name: ");
            newCust.LastName = Console.ReadLine();
            Console.WriteLine("Please enter a new User Name: ");
            newCust.UserName = Console.ReadLine();
            Console.WriteLine("Please enter a new password: "******"\nYou have been successfully added to the database! ");
        }
예제 #14
0
 public OrderlinesController(Game_RealmContext context)
 {
     _context = context;
 }
예제 #15
0
 public InventoriesController(Game_RealmContext context)
 {
     _context = context;
 }
예제 #16
0
 public LocationsController(Game_RealmContext context)
 {
     ctx = context;
 }
 public CustomersController(Game_RealmContext context)
 {
     _context = context;
 }
예제 #18
0
 public List <Model.Customer> LoadAllCustomers()
 {
     using Game_RealmContext ctx = new Game_RealmContext();
     return(ctx.Customer.ToList());
 }
예제 #19
0
 public List <Locations> LoadAllStores()
 {
     using Game_RealmContext context = new Game_RealmContext();
     return(context.Locations.ToList());
 }
예제 #20
0
 public List <Orders> LoadOrders()
 {
     using Game_RealmContext context = new Game_RealmContext();
     return(context.Orders.Include("Orderlines").Include("Customers").ToList());
 }
예제 #21
0
        public static Customer promtUserMenu(Game_RealmContext ctx, Customer cust)
        {
            var loc = new Locations();

            Console.WriteLine("What would you like to do? \n");
            Thread.Sleep(800);

            Console.WriteLine("\t1) New Customer\n" + "\t2) Search for Customer\n" + "\t3) Show Game GameRealm Locations\n" + "\t4) Place An Order\n" + "\t5) List Of All Games\n" + "\t6) Show all GameRealm Inventory\n" + "\t7) Quit?");

            int uChoice = 0;

            try
            {
                uChoice = int.Parse(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("Invalid entry, You must choose an option!");
            }
            switch (uChoice)
            {
            case 1:
                Console.WriteLine("\n");
                StoreCustomer.addCustomer(ctx);
                Thread.Sleep(600);
                Console.WriteLine("\n\n");
                promtUserMenu(ctx, cust);
                break;

            case 2:
                Console.WriteLine("\n");
                CustLookUp.customerSearch(ctx, cust);
                Thread.Sleep(600);
                Console.WriteLine("\n\n");
                promtUserMenu(ctx, cust);
                break;

            case 3:
                Console.WriteLine("\n");
                storeLocation.showLocation(ctx);
                Thread.Sleep(600);
                Console.WriteLine("\n\n");
                promtUserMenu(ctx, cust);
                break;

            case 4:
                Console.WriteLine("\n");
                Console.WriteLine("Are you a registered customer? (y/n)");
                placeOrders.buyGame(ctx, cust, loc);
                Thread.Sleep(600);
                Console.WriteLine("\n\n");
                promtUserMenu(ctx, cust);
                break;

            case 5:
                var listOfGames = new gameList();
                Console.WriteLine("\n");
                listOfGames.gameInventory();
                Console.WriteLine("\n\n");
                promtUserMenu(ctx, cust);
                break;

            case 6:
                ProductInventory.storeInventory(ctx);
                Thread.Sleep(900);
                promptUser.promtUserMenu(ctx, cust);
                break;

            case 7:
                System.Environment.Exit(0);
                break;

            default:
                Console.WriteLine("\n");
                promtUserMenu(ctx, cust);
                break;
            }
            return(cust);
        }
        public static Customer buyGame(Game_RealmContext ctx, Customer cust, Locations loc)
        {
            var choice = "";

            try
            {
                choice = Console.ReadLine();
            }
            catch (Exception)
            {
                Console.WriteLine("");
            }

            if (choice.ToUpper() == "Y")
            {
                cust = CustStorage.custLogin(ctx, cust);
            }

            else if (choice.ToUpper() == "N")
            {
                Console.WriteLine("You must be a user to place orders!\n");
                Thread.Sleep(800);
                Console.WriteLine("Please Login or Create a new account!\n");
                //Dont allow purchase until confirmation that they are registered with us.
                promptUser.promtUserMenu(ctx, cust);
            }
            else if (choice == "")
            {
                Console.WriteLine("You Must Enter something !\n");
                Thread.Sleep(800);
                Console.WriteLine("Please Login or Create a new account!\n");
                //Dont allow purchase until confirmation that they are registered with us.
                promptUser.promtUserMenu(ctx, cust);
            }
            else
            {
                Console.WriteLine("Invalid Entry!\n");
                Thread.Sleep(800);
                Console.WriteLine("Please Login or Create a new account!\n");
                //Dont allow purchase until confirmation that they are registered with us.
                promptUser.promtUserMenu(ctx, cust);
            }



            Console.WriteLine("Which store location would you like to purchase your game from?\n");
            Thread.Sleep(800);
            Console.WriteLine("Choose by StoreID: ");
            List <Locations> locations_list = ctx.Locations.ToList();


            foreach (var item in locations_list)
            {
                Console.WriteLine("StoreID: " + item.StoreId + " GameRealm Name: " + item.StoreName + "\nStreet: " + item.Street + "\nCity: " + item.City + "\nState: " + item.State + "\n\n");
            }



            int uInput = 0;

            while (true)
            {
                try
                {
                    uInput = int.Parse(Console.ReadLine());
                    if (ctx.Locations.Find(uInput) != null)
                    {
                        break;
                    }
                    else
                    {
                        Console.WriteLine("You Must Enter the correct GameRealm ID: ");
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("incorrect input, enter valid location ID!");
                }
            }

            Orders newOrder = new Orders();

            newOrder.Checkout   = 0;
            newOrder.StoreId    = uInput;
            newOrder.CustomerId = cust.CustomerId;
            newOrder.Time       = DateTime.Now;
            ctx.Orders.Add(newOrder);
            ctx.SaveChanges();
            ctx.Entry(newOrder).Reload();


            int nID = newOrder.OrderId;



            /*var storeID = ctx.Locations.FirstOrDefault(sid => sid.StoreId == uInput);*/
            loc = ctx.Locations.SingleOrDefault(c => c.StoreId == uInput);


            switch (uInput)
            {
            case 1:
                Console.WriteLine("\n");
                Console.WriteLine("Your store: Long Beach, Ca\n");
                Thread.Sleep(700);
                break;

            case 4:
                Console.WriteLine("\n");
                Console.WriteLine("Your store: Miami, Fl\n");
                Thread.Sleep(700);
                break;

            case 5:
                Console.WriteLine("\n");
                Console.WriteLine("Your store: New York, Ny\n");
                Thread.Sleep(700);
                break;

            case 6:
                Console.WriteLine("\n");
                Console.WriteLine("Your store: Dallas, Tx\n");
                Thread.Sleep(700);
                break;

            default:
                Console.WriteLine("\n");
                Console.WriteLine("Incorrect input, you must choose a store location!\n\n");
                Thread.Sleep(700);
                Console.WriteLine("Are you a registered customer? (y/n)");
                buyGame(ctx, cust, loc);
                break;
            }



            List <Games>  orderTotal = new List <Games>();
            List <Orders> finalCost  = new List <Orders>();


            var showInventory = new placeOrders();

            Console.WriteLine("Choose a game that you would you like to buy, based on GameID: \n\n");
            Thread.Sleep(900);
            showInventory.gameInventory();
            Thread.Sleep(800);
            Console.WriteLine("Choose GameID: ");
            int gameChoice = 0;

            Console.WriteLine("\n");

            try
            {
                gameChoice = int.Parse(Console.ReadLine());
            }
            catch (Exception)
            {
                Console.WriteLine("You Must Enter Some Data!");
            }



            /*var orderHist = ctx.Orderline*/
            var gameID = ctx.Games.FirstOrDefault(gChoice => gChoice.ProductId == gameChoice);



            if (gameID != null)
            {
                /*string uInput = "";*/


                Console.WriteLine($"You have chosen:\nGame Title: {gameID.Title} \nPrice: ${gameID.Price}\n");

                orderTotal.Add(gameID);

                Console.WriteLine("add another game to your cart? (y/n)");
                string answer = "";

                try
                {
                    answer = Console.ReadLine();
                }
                catch (Exception)
                {
                    Console.WriteLine("You Must Enter Some Data!");
                }

                Orderline tCost = new Orderline();

                tCost.ProductId = gameID.ProductId;
                tCost.OrderId   = nID;
                tCost.Quantity  = 1;
                ctx.Orderline.Add(tCost);
                ctx.SaveChanges();



                while (answer.ToUpper() == "Y")
                {
                    Orderline totalCost = new Orderline();

                    int count = 0;

                    Console.WriteLine("Choose GameID: ");
                    int gameChoice2 = 0;

                    try
                    {
                        gameChoice2 = int.Parse(Console.ReadLine());
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("You Must Enter Some Data!");
                    }

                    Console.WriteLine("\n");
                    var gameID2 = ctx.Games.FirstOrDefault(gChoice => gChoice.ProductId == gameChoice2);
                    orderTotal.Add(gameID2);

                    foreach (var item in orderTotal)
                    {
                        count++;
                    }
                    Thread.Sleep(1000);
                    Console.WriteLine($"You have chosen:\nGame Title: {gameID2.Title} \nPrice: ${gameID2.Price}\n");
                    Console.WriteLine(count + " Games in your cart!\n");

                    totalCost.ProductId = gameID2.ProductId;
                    totalCost.OrderId   = nID;
                    totalCost.Quantity  = 1;
                    ctx.Orderline.Add(totalCost);
                    ctx.SaveChanges();

                    Console.WriteLine("\nadd another game to your cart? (y/n)");
                    string answer2 = Console.ReadLine();
                    try
                    {
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("You must choose something!");
                    }
                    if (answer2.ToUpper() == "N")
                    {
                        break;
                    }
                }



                Console.WriteLine("Would you like to confirm your Purchase? (y/n)");
                var uChoice = Console.ReadLine();



                if (uChoice.ToUpper() == "Y")
                {
                    /*DateTime orederTime = DateTime.Now;
                     * Orders order = new Orders()
                     * {
                     *
                     *
                     *  StoreId = loc.StoreId,
                     *  CustomerId = cust.CustomerId,
                     *  Checkout = gameID.Price,
                     *  Time = DateTime.Now
                     * };
                     * ctx.Orders.Add(order);
                     * ctx.SaveChanges();*/

                    Console.WriteLine("Thank you for your purchase!\n");
                    Thread.Sleep(1000);

                    Console.WriteLine("Here is your order summary: \n");
                    foreach (var item in orderTotal)
                    {
                        Console.WriteLine($"Game: {item.Title}\nPrice: ${item.Price} \n");
                    }

                    ctx.Entry(newOrder).Reload();
                    Console.Write("Your total comes out to: $" + newOrder.Checkout);
                }



                else if (uChoice.ToUpper() == "N")
                {
                    Console.WriteLine("Ok, Well what would you like to do?");
                    Thread.Sleep(800);
                    Console.WriteLine("1) Main Menu\t\t2) Compete Purchase\t\t");
                    int userChoice = int.Parse(Console.ReadLine());

                    switch (userChoice)
                    {
                    case 1:
                        Console.WriteLine("\n");
                        promptUser.promtUserMenu(ctx, cust);
                        Thread.Sleep(600);
                        break;

                    case 2:
                        Console.WriteLine("\n");

                        Console.WriteLine("Thank you for your purchase!\n");
                        Thread.Sleep(1000);

                        Console.WriteLine("Here is your order summary: \n");
                        foreach (var item in orderTotal)
                        {
                            Console.WriteLine($"Game: {item.Title}\nPrice: ${item.Price} \n");
                        }

                        ctx.Entry(newOrder).Reload();
                        Console.Write("Your total comes out to: " + newOrder.Checkout);
                        Thread.Sleep(600);
                        Console.WriteLine("\n");
                        promptUser.promtUserMenu(ctx, cust);
                        break;

                    default:
                        Console.WriteLine($"{cust.FirstName} {cust.LastName} You must choose an option.");
                        Thread.Sleep(600);

                        break;
                    }
                }
            }


            else
            {
                Console.WriteLine("Invalid GameID! Please choose The proper GameID from the list of Games Shown.");
                Console.WriteLine("Are you a registered customer? (y/n)");
                placeOrders.buyGame(ctx, cust, loc);
            }


            return(cust);
        }
 public GamesController(Game_RealmContext context)
 {
     _context = context;
 }
예제 #24
0
        public static Customer custLogin(Game_RealmContext ctx, Customer cust)
        {
            cust = null;

            while (cust == null)
            {
                Console.WriteLine("Please Enter your credentials\n\n");
                Console.Write("Username: "******"";
                try
                {
                    userName = Console.ReadLine();
                }
                catch (Exception)
                {
                    Console.WriteLine("You must Enter in a Username!");
                }
                Console.Write("Password: "******"";
                try
                {
                    custPass = Console.ReadLine();
                }
                catch (Exception)
                {
                    Console.WriteLine("You must enter in a Password!");
                }
                Thread.Sleep(400);



                var customer = from sales in ctx.Customer
                               where sales.UserName == userName && sales.Password == custPass
                               select sales;

                cust = ctx.Customer.Where(c => c.UserName == userName && c.Password == custPass).SingleOrDefault();
            }


            /* Customer custID = ctx.Customer.Where(cid => cid.CustomerId == customerID).SingleOrDefault();*/
            if (cust.UserName.ToUpper() != null)
            {
                if (cust.Password != null)
                {
                    Console.WriteLine("\nWelcome back: " + cust.FirstName + " " + cust.LastName + "!\n");
                }
            }

            else if (cust.UserName == null)
            {
                Console.WriteLine("Username or Password is incorrect\n");
                Thread.Sleep(900);
                Console.WriteLine("Would you like to try again? (y/n)");
                var answer = Console.ReadLine();

                if (answer.ToUpper() == "Y")
                {
                    custLogin(ctx, cust);
                }
                else
                {
                    promptUser.promtUserMenu(ctx, cust);
                }
            }

            else if (cust.Password == null)
            {
                Console.WriteLine("Username or Password is incorrect\n");
                Thread.Sleep(900);
                Console.WriteLine("Would you like to try again? (y/n)");
                var answer = Console.ReadLine();

                if (answer.ToUpper() == "Y")
                {
                    custLogin(ctx, cust);
                }
                else
                {
                    promptUser.promtUserMenu(ctx, cust);
                }
            }

            else
            {
                Console.WriteLine("You Must Enter Something!");
                Thread.Sleep(900);
                promptUser.promtUserMenu(ctx, cust);
            }

            return(cust);
        }