Example #1
0
        public void Remove(int id)
        {
            var removeCust = ctx.Customer.Find(id);

            ctx.Customer.Remove(removeCust);
            ctx.SaveChanges();
        }
 public IActionResult Create([Bind("ProductId,Title,Genre,Release,Price,Quantity")] Games games)
 {
     if (ModelState.IsValid)
     {
         _context.Add(games);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(games));
 }
 public IActionResult Create([Bind("CustomerId,FirstName,LastName,Phone,Email,Street,City,State,ZipCode,Password,UserName")] Customer customer)
 {
     if (ModelState.IsValid)
     {
         ctx.Add(customer);
         ctx.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(customer));
 }
Example #4
0
 public IActionResult Create([Bind("StoreId,StoreName,Phone,Email,Street,City,State,ZipCode")] Locations locations)
 {
     if (ModelState.IsValid)
     {
         ctx.Add(locations);
         ctx.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     return(View(locations));
 }
 public IActionResult Create([Bind("InventoryId,StoreId,ProductId,Quantity,Title")] Inventory inventory)
 {
     if (ModelState.IsValid)
     {
         _context.Add(inventory);
         _context.SaveChanges();
         return(RedirectToAction(nameof(Index)));
     }
     ViewData["ProductId"] = new SelectList(_context.Games, "ProductId", "Title", inventory.ProductId);
     ViewData["StoreId"]   = new SelectList(_context.Locations, "StoreId", "StoreName", inventory.StoreId);
     return(View(inventory));
 }
 public void Remove(int id)
 {
     try
     {
         var toRemove = ctx.Orders.Find(id);
         ctx.Remove(toRemove);
         ctx.SaveChanges();
     }
     catch (DbUpdateException)
     {
         return;
     }
 }
Example #7
0
        public IActionResult Create([Bind("ProductId,OrderId,Quantity")] Orderline orderline)
        {
            var lastOrderPlaced = ordsDAL.preOrder();

            orderline.OrderId = lastOrderPlaced.OrderId;
            if (ModelState.IsValid)
            {
                _context.Orderline.Add(orderline);
                _context.SaveChanges();
                return(RedirectToAction(nameof(Create)));
            }
            ViewData["Quantity"]  = new SelectList(_context.Orders, "Quantity", "Quantity", orderline.OrderId);
            ViewData["ProductId"] = new SelectList(_context.Games, "ProductId", "Title", orderline.ProductId);
            return(View(orderline));
        }
Example #8
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)));
        }
        private static void TylerMain(string[] args)
        {
            Customer c = new Customer();


            c.FirstName = Console.ReadLine();

            c.LastName = Console.ReadLine();

            c.Email = Console.ReadLine();

            ctx.Customer.Add(c);

            ctx.SaveChanges();
        }
Example #10
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();
        }
Example #11
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();
        }
Example #12
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();
        }
        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! ");
        }
        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);
        }