示例#1
0
 public ProductRepository(Project0Context context)
 {
     _context = context;
 }
示例#2
0
        static void Main(string[] args)
        {
            var screenIo = new Program().GetScreenSelection();

            if (screenIo == 'e')
            {
                Console.WriteLine("Please enter your employee id:");
                int IdEntered = Int32.Parse(Console.ReadLine());

                using (var context = new Project0Context(Options))
                {
                    var query    = from Employees in context.Employees where Employees.EmployeeId == IdEntered select Employees;
                    var employee = query.FirstOrDefault();
                    Console.WriteLine("Welcome " + employee.FirstName);
                    Console.WriteLine("Please select the function you would like to use:\n"
                                      + "1: Add New Customer.\n"
                                      + "2: Search For a Customer by (Last) Name\n"
                                      + "3: Search For a Customer by Id Number\n"
                                      + "4: Place an Order for a Customer\n"
                                      + "5: Display a Store's Inventory\n"
                                      + "6: Display Order History for a Store\n"
                                      + "7: Display the Company Directory");
                    int menuChoice = int.Parse(Console.ReadLine());

                    switch (menuChoice)
                    {
                    case 1:
                        var Customer = new CustomerRepository();
                        Customer.InsertCustomer();
                        break;

                    case 2:
                        break;

                    case 3:
                        break;

                    case 4:
                        break;

                    case 5:
                        Console.Write("\nStore List: \n");
                        var store  = new Stores();
                        var query2 = from Stores in context.Stores
                                     select Stores;
                        Console.Write("\nStore Id | Store Address | City | State\n");
                        foreach (var x in query2)
                        {
                            Console.Write("{0}, {1}, {2}, {3}\n", x.StoreId, x.StoreStAddress, x.StoreCity, x.StoreState);
                        }
                        Console.Write("\nEnter Store Id: ");
                        int menuChoice2 = int.Parse(Console.ReadLine());
                        var query3      = from StoreInventory in context.StoreInventory //.Include("ItemId")
                                                                                        //   .Where(b => b.ItemId.Equals(context.ItemList))
                                          where StoreInventory.StoreNumber == menuChoice2
                                          select StoreInventory;
                        //   .Include("ItemId").Where(b => b.ItemId.Equals(context.ItemList));
                        //var query4 = query3.Include("ItemId").Where(b => b.ItemId.Equals(context.ItemList));

                        foreach (var x in query3)
                        {
                            Console.Write("\n{0}\t{1}\n", x.ItemId, x.Quantity);
                        }
                        break;

                    case 6:
                        break;

                    case 7:
                        break;

                    default:
                        Console.WriteLine("Program Ends.");
                        break;
                    }
                }
            }
            else if (screenIo == 'c')
            {
            }
            else
            {
                Console.WriteLine("Program Ends");
            }

            Console.WriteLine("Hello World!");
        }
示例#3
0
        public static async Task RunUI(Project0Context dbContext)
        {
            //Establish contexts to the four domains
            var custContext = new DbRepo.CustomerRepo(dbContext);
            var prodContext = new DbRepo.ProductRepo(dbContext);
            var locContext  = new DbRepo.LocationRepo(dbContext);
            var ordContext  = new DbRepo.OrderRepo(dbContext);

            string storeName = " ____  ____  __  ____  ____  _  _   __   __ _   __    ___  ____  ____ \n" +
                               "/ ___)(_  _)/  \\(  _ \\(  __)( \\/ ) / _\\ (  ( \\ / _\\  / __)(  __)(  _ \\\n" +
                               "\\___ \\  )( (  O ))   / ) _) / \\/ \\/    \\/    //    \\( (_ \\ ) _)  )   /\n" +
                               "(____/ (__) \\__/(__\\_)(____)\\_)(_/\\_/\\_/\\_)__)\\_/\\_/ \\___/(____)(__\\_)\n";

            while (true)
            {
                Console.Clear();
                Console.WriteLine(storeName);
                Console.WriteLine();

                Console.WriteLine("1:\tAdd a customer");
                Console.WriteLine("2:\tPerform Searches and Displays");
                Console.WriteLine("3:\tPlace an order");
                Console.WriteLine("4:\tSave to file");
                Console.WriteLine("5:\tQuit");
                Console.WriteLine();
                Console.Write("Enter a valid menu option: ");
                var input = Console.ReadLine();
                if (input == "1")
                {
                    string firstName = null;
                    string lastName  = null;
                    string address   = null;

                    Console.Clear();
                    Console.WriteLine(storeName);
                    Console.WriteLine("Add a customer menu\n");

                    while (firstName == null)
                    {
                        Console.Write("Enter a first name: ");
                        firstName = Console.ReadLine();
                        if (firstName == "")
                        {
                            firstName = null;
                        }
                    }
                    while (lastName == null)
                    {
                        Console.Write("Enter a last name: ");
                        lastName = Console.ReadLine();
                        if (lastName == "")
                        {
                            lastName = null;
                        }
                    }
                    while (address == null)
                    {
                        Console.Write("Enter an address: ");
                        address = Console.ReadLine();
                        if (address == "")
                        {
                            address = null;
                        }
                    }
                    Console.WriteLine($"\nCreating a new customer with:\nFirst Name:  {firstName}\nLast Name:  {lastName}\nAddress:  {address}");

                    try
                    {
                        var newCustomer = new dom.Customer(firstName, lastName, address);
                        custContext.AddCustomer(newCustomer);
                        custContext.Save();
                        var dbCustomerId = custContext.GetCustomers(firstName, lastName).Last().CustID;
                        Console.WriteLine($"The customer has been successfully added.\nID:\t{dbCustomerId}\n");

                        Console.WriteLine("Press any key to continue.");
                        Console.ReadKey();
                    }
                    catch (ArgumentNullException ex)
                    {
                        Console.WriteLine(ex.Message);
                        s_logger.Info(ex);
                    }
                }
                else if (input == "2")
                {
                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine(storeName);
                        Console.WriteLine("Search and Display Menu\n");

                        Console.WriteLine("1:\tSearch and Display Customers by Name");
                        Console.WriteLine("2:\tDisplay Locations");
                        Console.WriteLine("3:\tDisplay all Orders for a Customer");
                        Console.WriteLine("4:\tDisplay all Orders for a Location");
                        Console.WriteLine("5:\tDisplay Details of an Order");
                        Console.WriteLine("6:\tLeave Menu");
                        Console.WriteLine();

                        Console.Write("Enter a valid menu option: ");
                        var inputMenu2 = Console.ReadLine();
                        if (inputMenu2 == "1")
                        {
                            string firstNameSearch = null;
                            string lastNameSearch  = null;

                            Console.Clear();
                            Console.WriteLine(storeName);
                            Console.WriteLine("Search and Display Customers by Name\n");

                            Console.WriteLine("Enter a First Name to search:");
                            Console.Write("\t(or leave empty): ");
                            firstNameSearch = Console.ReadLine();
                            if (firstNameSearch == "")
                            {
                                firstNameSearch = null;
                            }

                            Console.WriteLine("Enter a Last Name to search:");
                            Console.Write("\t(or leave empty): ");
                            lastNameSearch = Console.ReadLine();
                            if (lastNameSearch == "")
                            {
                                lastNameSearch = null;
                            }

                            Console.WriteLine($"\nSearching for Customers with\n\tFirst Name: {firstNameSearch}\n\tLast Name: {lastNameSearch}\n\nResults:");
                            Console.WriteLine();
                            var customersSearched = custContext.GetCustomers(firstNameSearch, lastNameSearch).ToList();
                            foreach (dom.Customer cust in customersSearched)
                            {
                                Console.WriteLine(cust.ToString() + "\n");
                            }

                            Console.WriteLine("\nPress any key to continue.");
                            Console.ReadKey();
                        }
                        else if (inputMenu2 == "2")
                        {
                            Console.Clear();
                            Console.WriteLine(storeName);
                            Console.WriteLine("Locations:\n");

                            var locations = locContext.GetLocations().ToList();
                            foreach (dom.Location item in locations)
                            {
                                Console.WriteLine(item.ToString() + "\n");
                            }
                            Console.WriteLine("\nPress any key to continue.");
                            Console.ReadKey();
                        }
                        else if (inputMenu2 == "3")
                        {
                            string inputMenu2Entry;
                            int    custId = 0;
                            bool   isInt  = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine(storeName);
                                Console.WriteLine("Display All Orders for a Customer\n");

                                Console.Write("Enter a Customer ID: ");
                                inputMenu2Entry = Console.ReadLine();
                                isInt           = Int32.TryParse(inputMenu2Entry, out custId);
                            }while (!isInt);

                            var results = ordContext.GetOrdersByCustomer(custId: custId).ToList();
                            if (results.Count > 0)
                            {
                                foreach (dom.Order ord in results)
                                {
                                    Console.WriteLine(ord.ToString() + "\n");
                                }
                            }
                            else
                            {
                                Console.WriteLine($"No results matching CustomerID {custId}");
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (inputMenu2 == "4")
                        {
                            string inputMenu3Entry;
                            int    locId = 0;
                            bool   isInt = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine(storeName);
                                Console.WriteLine("Display All Orders for a Location\n");

                                Console.Write("Enter a Location ID: ");
                                inputMenu3Entry = Console.ReadLine();
                                isInt           = Int32.TryParse(inputMenu3Entry, out locId);
                            }while (!isInt);

                            var results = ordContext.GetOrdersByLocation(locId).ToList();
                            if (results.Count > 0)
                            {
                                foreach (dom.Order ord in results)
                                {
                                    Console.WriteLine(ord.ToString() + "\n");
                                }
                            }
                            else
                            {
                                Console.WriteLine($"No results matching LocationID {locId}");
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (inputMenu2 == "5")
                        {
                            string inputMenu4Entry;
                            int    ordId = 0;
                            bool   isInt = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine(storeName);
                                Console.WriteLine("Display Details of an Order:\n");

                                Console.Write("Enter a Order ID: ");
                                inputMenu4Entry = Console.ReadLine();
                                isInt           = Int32.TryParse(inputMenu4Entry, out ordId);
                            }while (!isInt);

                            var result = ordContext.GetOrderById(ordId).ToList().FirstOrDefault();
                            if (result == null)
                            {
                                Console.WriteLine($"No results matching OrderID {ordId}");
                            }
                            else
                            {
                                Console.WriteLine(result.ToString());
                                Console.WriteLine(result.BasketToString());
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (inputMenu2 == "6")
                        {
                            break;
                        }
                    }
                }
                else if (input == "3")
                {
                    string inputStr;
                    int    custId = 0;
                    int    locId  = 0;
                    bool   isInt  = false;


                    do
                    {
                        Console.Clear();
                        Console.WriteLine(storeName);
                        Console.WriteLine("Place an Order Menu\n");

                        Console.Write("Enter a Customer ID: ");
                        inputStr = Console.ReadLine();
                        isInt    = Int32.TryParse(inputStr, out custId);
                    }while (!isInt);

                    var cust = custContext.GetCustomers(custId: custId).FirstOrDefault();
                    if (cust == null)
                    {
                        Console.WriteLine($"Customer {custId} does not exist.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Customer found:\n");
                        Console.WriteLine(cust.ToString());
                    }

                    isInt = false;
                    do
                    {
                        Console.Clear();
                        Console.WriteLine(storeName);
                        Console.WriteLine("Place an Order Menu\n");

                        Console.WriteLine($"Enter a Customer ID: {custId}");
                        Console.WriteLine("Customer found:\n");
                        Console.WriteLine(cust.ToString());

                        Console.Write("Enter a Location ID: ");
                        inputStr = Console.ReadLine();
                        isInt    = Int32.TryParse(inputStr, out locId);
                    }while (!isInt);

                    var loc = locContext.GetLocations(locId).FirstOrDefault();
                    if (loc == null)
                    {
                        Console.WriteLine($"Location {locId} does not exist.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Location found:\n");
                        Console.WriteLine(loc.ToString());
                    }
                    bool abort = false;
                    do
                    {
                        Console.Write("Would you like to continue? (YES/NO): ");
                        string answer = Console.ReadLine();
                        if (answer.ToUpper() == "YES" || answer.ToUpper() == "Y")
                        {
                            break;
                        }
                        else if (answer.ToUpper() == "NO" || answer.ToUpper() == "N")
                        {
                            abort = true;
                        }
                    }while (!abort);

                    if (!abort)
                    {
                        try
                        {
                            var ord = new dom.Order(cust, loc, 0);
                            ordContext.AddOrder(ord);
                            ordContext.Save();
                            ord = ordContext.GetOrdersByCustomer(cust.CustID).Last();


                            int prodId = 0;

                            bool done = false;
                            do
                            {
                                do
                                {
                                    prodId = 0;

                                    Console.Clear();
                                    Console.WriteLine(storeName);
                                    Console.WriteLine("Place an Order Menu\n");

                                    /*Console.WriteLine($"Customer:\n{cust.ToString()}");
                                     * Console.WriteLine($"Location:\n{loc.ToString()}");
                                     * Console.WriteLine();*/
                                    Console.WriteLine(".____________________.");
                                    Console.WriteLine("| Location Inventory |");
                                    Console.WriteLine("|____________________|");
                                    Console.WriteLine(loc.InventoryToString());
                                    Console.WriteLine();
                                    Console.WriteLine("._____________.");
                                    Console.WriteLine("| Your basket |");
                                    Console.WriteLine("|_____________|");
                                    Console.WriteLine(ord.BasketToString());

                                    Console.Write("\n\nEnter a Product Id, or DONE if finished: ");
                                    inputStr = Console.ReadLine();
                                    if (inputStr.ToUpper() == "DONE")
                                    {
                                        done  = true;
                                        isInt = true;
                                    }
                                    else
                                    {
                                        isInt = Int32.TryParse(inputStr, out prodId);
                                    }
                                }while (!isInt);
                                if (!done)
                                {
                                    var prod = prodContext.GetProducts(prodId).FirstOrDefault();
                                    if (prod == null)
                                    {
                                        Console.WriteLine($"Product {prodId} does not exist");
                                        Console.WriteLine("\nPress any key to continue.");
                                        Console.ReadKey();
                                    }
                                    else if (!loc.FindItemById(prodId))
                                    {
                                        Console.WriteLine($"Product {prodId} is not in this location's inventory");
                                        Console.WriteLine("\nPress any key to continue.");
                                        Console.ReadKey();
                                    }
                                    else
                                    {
                                        bool addRemoveTF = true;
                                        do
                                        {
                                            Console.Write("Do you want to add or remove this Product to/from the basket? (ADD, REMOVE) ");
                                            string addOrRemove = Console.ReadLine();
                                            if (addOrRemove.ToUpper() == "ADD")
                                            {
                                                addRemoveTF = true;
                                                break;
                                            }
                                            if (addOrRemove.ToUpper() == "REMOVE")
                                            {
                                                addRemoveTF = false;
                                                break;
                                            }
                                        }while (true);

                                        bool isIntQuantity = false;
                                        int  quantity      = 0;
                                        do
                                        {
                                            Console.Write("Enter a quantity: ");
                                            inputStr      = Console.ReadLine();
                                            isIntQuantity = Int32.TryParse(inputStr, out quantity);
                                        }while (!isIntQuantity);

                                        if (addRemoveTF == true)
                                        {
                                            if (loc.AdjustQuantity(prod, -1 * quantity))
                                            {
                                                ord.basket.Add(prod, quantity);
                                                Console.WriteLine($"Added {quantity} {prod.ProductName}s to basket.");
                                                Console.WriteLine("\nPress any key to continue.");
                                                Console.ReadKey();
                                            }
                                        }
                                        else// if(addRemoveTF == false)
                                        {
                                            if (ord.AdjustQuantity(prod, -1 * quantity))
                                            {
                                                dom.Product prodInInv = null;
                                                foreach (KeyValuePair <dom.Product, int> item in loc.inventory)
                                                {
                                                    if (item.Key.ProductID == prod.ProductID)
                                                    {
                                                        prodInInv = item.Key;
                                                    }
                                                }
                                                if (prodInInv == null)
                                                {
                                                    Console.WriteLine("Something unexpected went wrong.");
                                                }
                                                else
                                                {
                                                    loc.inventory[prodInInv] += quantity;
                                                    Console.WriteLine($"Removed {quantity} {prod.ProductName}s from basket.");
                                                }

                                                Console.WriteLine("\nPress any key to continue.");
                                                Console.ReadKey();
                                            }
                                        }
                                    }
                                }
                            }while (!done);
                            ordContext.AddBasket(ord);
                            ordContext.Save();

                            locContext.UpdateInventory(loc);
                            locContext.Save();

                            Console.Clear();
                            Console.WriteLine(storeName);
                            Console.WriteLine($"Order Complete.\n");
                            Console.WriteLine(ord.ToString());
                            Console.WriteLine(ord.BasketToString());
                        }
                        catch (ArgumentNullException ex)
                        {
                            Console.WriteLine(ex.Message);
                            s_logger.Info(ex);
                        }
                    }
                    Console.WriteLine("\nPress any key to continue.");
                    Console.ReadKey();
                }
                else if (input == "4")
                {
                    try
                    {
                        var customers = custContext.GetCustomers().ToList();
                        await Serialize.JsonToFileAsync(@"C:\revature\greg-project0\json\custData.json", customers);

                        Console.WriteLine("Customers successfully saved.");

                        var products = prodContext.GetProducts().ToList();
                        await Serialize.JsonToFileAsync(@"C:\revature\greg-project0\json\prodData.json", products);

                        Console.WriteLine("Products successfully saved.");

                        var locations = locContext.GetLocations().ToList();
                        await Serialize.JsonToFileAsync(@"C:\revature\greg-project0\json\locData.json", locations);

                        Console.WriteLine("Locations successfully saved.");

                        var orders = ordContext.GetOrders().ToList();
                        await Serialize.JsonToFileAsync(@"C:\revature\greg-project0\json\ordData.json", orders);

                        Console.WriteLine("Orders successfully saved.");

                        Console.WriteLine("\nPress any key to continue.");
                        Console.ReadKey();
                    }
                    catch (IOException ex)
                    {
                        Console.WriteLine($"Error while saving: {ex.Message}");
                        s_logger.Error(ex, "Error while saving.");
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine($"Unknown Error while saving: {ex.Message}");
                        s_logger.Error(ex, "Unknown Error while saving.");
                    }
                }
                else if (input == "5")
                {
                    Console.WriteLine("Closing application...");
                    Console.WriteLine("\nPress any key to continue.");
                    Console.ReadKey();
                    break;
                }
            }
        }
        public static void Run(Project0Context dbContext)
        {
            //establish contexts with domains
            var CusCon = new ef.CustomerRep(dbContext);
            var MerCon = new ef.MerchRep(dbContext);
            var StoCon = new ef.StoreRep(dbContext);
            var OrdCon = new ef.OrderRep(dbContext);

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Manager\n");
                Console.WriteLine();

                Console.WriteLine("1:\tAdd a body");
                Console.WriteLine("2:\tStart a Search");
                Console.WriteLine("3:\tWant to Order Something?");
                Console.WriteLine("4:\tFare Thee Well");
                Console.WriteLine();
                Console.WriteLine("What do you want to do?");
                var input = Console.ReadLine();
                if (input == "1")
                {
                    string fname = null;
                    string lname = null;

                    Console.Clear();
                    Console.WriteLine("Adding a Customer\n");

                    while (fname == null)
                    {
                        Console.Write("Enter First name: ");
                        fname = Console.ReadLine();
                        if (fname == "")
                        {
                            fname = null;
                        }
                    }
                    while (lname == null)
                    {
                        Console.Write("Enter Last name: ");
                        lname = Console.ReadLine();
                        if (lname == "")
                        {
                            lname = null;
                        }
                    }
                    Console.WriteLine($"\nCreating a new Customer with \nFirst Name: {fname}\nLast Name: {lname}");

                    try
                    {
                        var newCus = new lib.Customer(fname, lname);
                        CusCon.AddCust(newCus);
                        CusCon.why();
                        var dbCusId = CusCon.GetCustomers(fname, lname).Last().CustomerID;
                        Console.WriteLine($"Customer has been added.\nID: {dbCusId}");

                        Console.WriteLine("Press a key to keep going");
                        Console.ReadKey();
                    }
                    catch (ArgumentException ex)
                    {
                        Console.WriteLine(ex.Message);
                    }
                }
                else if (input == "2")
                {
                    while (true)
                    {
                        Console.Clear();
                        Console.WriteLine("Search for something Screen");

                        Console.WriteLine("1:\tSearch for Customer");
                        Console.WriteLine("2:\tSearch for Store");
                        Console.WriteLine("3:\tSearch for Orders for Customer");
                        Console.WriteLine("4:\tSearch for Orders for Store");
                        Console.WriteLine("5:\tSearch for Order Details");
                        Console.WriteLine("6:\tLet Me Out");
                        Console.WriteLine();

                        Console.WriteLine("What do you want to do?");
                        var input2 = Console.ReadLine();
                        if (input2 == "1")
                        {
                            string fnamesearch = null;
                            string lnamesearch = null;
                            Console.Clear();
                            Console.WriteLine("Searching for Customers\n");
                            Console.WriteLine("Give me a First Name to search for ");
                            Console.WriteLine("\tor you could give me no name: ");
                            fnamesearch = Console.ReadLine();
                            if (fnamesearch == null)
                            {
                                fnamesearch = null;
                            }

                            Console.WriteLine("Now give me a Last Name to search for ");
                            Console.WriteLine("\tor you can leave nothing here also: ");
                            lnamesearch = Console.ReadLine();
                            if (lnamesearch == null)
                            {
                                lnamesearch = null;
                            }
                            Console.WriteLine($"So, I am searching for {fnamesearch} {lnamesearch} right? Give me a second.");
                            Console.WriteLine();
                            var cusSearch = CusCon.GetCustomers(fnamesearch, lnamesearch).ToList();
                            foreach (lib.Customer item in cusSearch)
                            {
                                Console.WriteLine(item.ToString() + "\n");
                            }
                            Console.WriteLine("\nPress something to continue");
                            Console.ReadKey();
                        }
                        else if (input2 == "2")
                        {
                            Console.Clear();
                            Console.WriteLine("Store: \n");
                            var sto = StoCon.GetStores().ToList();
                            foreach (lib.Store item in sto)
                            {
                                Console.WriteLine(item.ToString() + "\n");
                            }
                            Console.WriteLine("\nPunch a key to keep moving");
                            Console.ReadKey();
                        }
                        else if (input2 == "3")
                        {
                            string input2key;
                            int    custId = 0;
                            bool   isInt  = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine("Display All Orders for a Customer\n");

                                Console.Write("Enter a Customer ID: ");
                                input2key = Console.ReadLine();
                                isInt     = Int32.TryParse(input2key, out custId);
                            }while (!isInt);

                            var results = OrdCon.GetOrdersByCust(id: custId).ToList();
                            if (results.Count > 0)
                            {
                                foreach (lib.Order ord in results)
                                {
                                    Console.WriteLine(ord.ToString() + "\n");
                                }
                            }
                            else
                            {
                                Console.WriteLine($"No results matching CustomerID {custId}");
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (input2 == "4")
                        {
                            string input2key;
                            int    stoId = 0;
                            bool   isInt = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine("Display All Orders for a Location\n");

                                Console.Write("Enter a Location ID: ");
                                input2key = Console.ReadLine();
                                isInt     = Int32.TryParse(input2key, out stoId);
                            }while (!isInt);

                            var results = OrdCon.GetOrdersByStore(stoId).ToList();
                            if (results.Count > 0)
                            {
                                foreach (lib.Order ord in results)
                                {
                                    Console.WriteLine(ord.ToString() + "\n");
                                }
                            }
                            else
                            {
                                Console.WriteLine($"No results matching LocationID {stoId}");
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (input2 == "5")
                        {
                            string input2key;
                            int    ordId = 0;
                            bool   isInt = false;
                            do
                            {
                                Console.Clear();
                                Console.WriteLine("Display Details of an Order:\n");

                                Console.Write("Enter a Order ID: ");
                                input2key = Console.ReadLine();
                                isInt     = Int32.TryParse(input2key, out ordId);
                            }while (!isInt);

                            var result = OrdCon.GetOrdersByID(ordId).ToList().FirstOrDefault();
                            if (result == null)
                            {
                                Console.WriteLine($"No results matching OrderID {ordId}");
                            }
                            else
                            {
                                Console.WriteLine(result.ToString());
                                Console.WriteLine(result.OrderToString());
                            }
                            Console.WriteLine("Press any key to continue.");
                            Console.ReadKey();
                        }
                        else if (input2 == "6")
                        {
                            break;
                        }
                    }
                }
                else if (input == "3")
                {
                    string inputStr;
                    int    custId = 0;
                    int    stoId  = 0;
                    bool   isInt  = false;


                    do
                    {
                        Console.Clear();
                        Console.WriteLine("Place an Order Menu\n");

                        Console.Write("Enter a Customer ID: ");
                        inputStr = Console.ReadLine();
                        isInt    = Int32.TryParse(inputStr, out custId);
                    }while (!isInt);

                    var cust = CusCon.GetCustomers(cusid: custId).FirstOrDefault();
                    if (cust == null)
                    {
                        Console.WriteLine($"Customer {custId} does not exist.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Customer found:\n");
                        Console.WriteLine(cust.ToString());
                    }

                    isInt = false;
                    do
                    {
                        Console.Clear();
                        Console.WriteLine("Place an Order Menu\n");

                        Console.WriteLine($"Enter a Customer ID: {custId}");
                        Console.WriteLine("Customer found:\n");
                        Console.WriteLine(cust.ToString());

                        Console.Write("Enter a Location ID: ");
                        inputStr = Console.ReadLine();
                        isInt    = Int32.TryParse(inputStr, out stoId);
                    }while (!isInt);

                    var loc = StoCon.GetStores(stoId).FirstOrDefault();
                    if (loc == null)
                    {
                        Console.WriteLine($"Store {stoId} does not exist.");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("Store found:\n");
                        Console.WriteLine(loc.ToString());
                    }
                    bool abort = false;
                    do
                    {
                        Console.Write("Would you like to continue? (YES/NO): ");
                        string answer = Console.ReadLine();
                        if (answer.ToUpper() == "YES")
                        {
                            break;
                        }
                        else if (answer.ToUpper() == "NO")
                        {
                            abort = true;
                        }
                    }while (!abort);

                    if (!abort)
                    {
                        try
                        {
                            var ord = new lib.Order(cust, loc, 0);
                            OrdCon.Order(ord);
                            OrdCon.EndMe();
                            ord = OrdCon.GetOrdersByCust(cust.CustomerID).Last();


                            int prodId = 0;

                            bool done = false;
                            do
                            {
                                do
                                {
                                    prodId = 0;

                                    Console.Clear();
                                    Console.WriteLine("Place an Order Menu\n");
                                    Console.WriteLine($"Customer:\n{cust.ToString()}");
                                    Console.WriteLine($"Store:\n{loc.ToString()}");
                                    Console.WriteLine();
                                    Console.WriteLine("Store inventory:");
                                    Console.WriteLine(loc.InventoryToString());
                                    Console.WriteLine();
                                    Console.WriteLine("Your basket:");
                                    Console.WriteLine(ord.OrderToString());

                                    Console.Write("Enter a Product Id, or DONE if finished: ");
                                    inputStr = Console.ReadLine();
                                    if (inputStr.ToUpper() == "DONE")
                                    {
                                        done  = true;
                                        isInt = true;
                                    }
                                    else
                                    {
                                        isInt = Int32.TryParse(inputStr, out prodId);
                                    }
                                }while (!isInt);
                                if (!done)
                                {
                                    var prod = MerCon.GetMerch().FirstOrDefault();
                                    if (prod == null)
                                    {
                                        Console.WriteLine($"Merch {prodId} does not exist");
                                        Console.WriteLine("\nPress any key to continue.");
                                        Console.ReadKey();
                                    }

                                    /*else if (!loc.FindItemById(prodId))
                                     * {
                                     *  Console.WriteLine($"Merch {prodId} is not in this location's inventory");
                                     *  Console.WriteLine("\nPress any key to continue.");
                                     *  Console.ReadKey();
                                     * }*/
                                    else
                                    {
                                        bool isIntQuantity = false;
                                        int  quantity      = 0;
                                        do
                                        {
                                            Console.Write("Enter a quanity: ");
                                            inputStr      = Console.ReadLine();
                                            isIntQuantity = Int32.TryParse(inputStr, out quantity);
                                        }while (!isIntQuantity);
                                        if (loc.ChangeStock(prod, -1 * quantity))
                                        {
                                            //ord.details.Add(prod, quantity);
                                            Console.WriteLine($"Added {quantity} {prod.MerchName}s to Order.");
                                            Console.WriteLine("\nPress any key to continue.");
                                            Console.ReadKey();
                                        }
                                    }
                                }
                            }while (!done);
                            OrdCon.AddOrder(ord);
                            OrdCon.EndMe();

                            Console.Clear();
                            Console.WriteLine($"Order Complete.\n");
                            Console.WriteLine(ord.ToString());
                            Console.WriteLine(ord.OrderToString());
                        }
                        catch (ArgumentNullException ex)
                        {
                            Console.WriteLine(ex.Message);
                        }
                    }
                    Console.WriteLine("\nPress any key to continue.");
                    Console.ReadKey();
                }
                else if (input == "4")
                {
                    Console.WriteLine("Alright, See you next time");
                    Console.WriteLine("\n Press any key to leave");
                    Console.ReadKey();
                    break;
                }
            }
        }
示例#5
0
 /// <summary>
 /// Checks the database to see if the name given is already a product
 /// </summary>
 /// <param name="name">Name of the Product</param>
 /// <returns>true if product name exists, false otherwise</returns>
 public bool IsProduct(string name)
 {
     // get the context of the db
     using var context = new Project0Context(_dbContext);
     return(context.Products.Any(p => p.Name == name));
 }
 public CustomerController(ICustomerRepository customerRepo, IStoreRepository storeRepo, Project0Context db)
 {
     Repo      = customerRepo;
     StoreRepo = storeRepo;
     _db       = db;
 }
 public OrderRepository(Project0Context context)
 {
     _context = context;
 }
示例#8
0
        #pragma warning restore CS0618 // Type or member is obsolete
        static void Main(string[] args)
        {
            var      Repo      = new FrameworkRepo();
            string   curr_name = "";
            string   curr_email;
            int      curr_cart;
            DateTime newt = DateTime.Now;


            var optionsBuilder = new DbContextOptionsBuilder <Project0Context>();

            optionsBuilder.UseSqlServer(Secret.ConnectionString);
            //optionsBuilder.UseLoggerFactory(AppLoggerFactory); This works but spams the console with data.
            var options = optionsBuilder.Options;

            Console.WriteLine("Welcome to Comic League United the 7th largest comic supply store in the tri-state area.");
            Console.WriteLine("Please login in order make a new customer. ");
            Console.WriteLine("Please enter Customer name now. ");
            curr_name = Console.ReadLine();
            Console.WriteLine("Please enter Customer email now. ");
            curr_email = Console.ReadLine();

            using (var dbContext = new Project0Context(options))
            {
                var store = dbContext.Customer.FirstOrDefault(x => x.Name == curr_name || x.Email == curr_email);
                if (store == null)
                {
                    Console.WriteLine("Please enter your store location now. ");
                    string temp = Console.ReadLine();
                    Repo.AddCustomer(dbContext, curr_name, curr_email, temp);
                    dbContext.SaveChanges();
                    Console.WriteLine("Welcome New Customer. ");
                }
                else
                {
                    Console.WriteLine("Welcome Back " + curr_name);
                }
                var cart = new Orders();
                cart.CustomerId = store.CustomerId;
                cart.OrderTime  = newt;
                dbContext.Add(cart);
                dbContext.SaveChanges();
                curr_cart = cart.OrdersId;
                Console.ReadKey();
            }

            while (true)
            {
                Repo.MainMenu();
                string choice = "11";
                string temp   = "";


                try
                {
                    choice = Console.ReadLine();
                    Console.Clear();
                    if (choice == "0")
                    {
                        break;
                    }
                    else if (choice == "1")
                    {
                        choice = "11";
                        Console.WriteLine("1: Add a Store");
                        Console.WriteLine("2: Delete a Store");
                        Console.WriteLine("3: Update a Store");
                        choice = Console.ReadLine();
                        Console.Clear();
                        if (choice == "1")
                        {
                            Console.WriteLine("Please enter a Store Name to add");
                            temp = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.AddStore(dbContext, temp);
                            }
                        }
                        else if (choice == "2")
                        {
                            Console.WriteLine("Please enter a Store Name to delete");
                            temp = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.DeleteStore(dbContext, temp);
                            }
                        }
                        else if (choice == "3")
                        {
                            Console.WriteLine("Please enter a Store Name to update");
                            temp = Console.ReadLine();
                            Console.WriteLine("Please enter the new name. ");
                            string temp2 = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.UpdateStore(dbContext, temp, temp2);
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Please pick a valid option. ");
                        }
                    }
                    else if (choice == "2")
                    {
                        choice = "11";
                        Console.WriteLine("1: Show All Stores. ");
                        Console.WriteLine("2: Show One Store. ");
                        choice = Console.ReadLine();
                        Console.Clear();
                        if (choice == "1")
                        {
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.ShowStores(dbContext);
                                Console.ReadKey();
                            }
                        }
                        else if (choice == "2")
                        {
                            Console.WriteLine("Please enter the store name. ");
                            temp = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.ShowStores(dbContext, temp);
                                Console.ReadKey();
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Please pick a valid option. ");
                        }
                    }
                    else if (choice == "3")
                    {
                        choice = "11";
                        Console.WriteLine("1: Add a Product");
                        Console.WriteLine("2: Delete a Product");
                        Console.WriteLine("3: Update a Product");
                        choice = Console.ReadLine();
                        Console.Clear();
                        if (choice == "1")
                        {
                            string  placeholder;
                            int     inv   = 1;
                            decimal price = 5.00m;
                            int     id;
                            Console.WriteLine("Please enter a Product Name.");
                            placeholder = Console.ReadLine();
                            Console.WriteLine("Please enter the number of products in inventory.");
                            temp = Console.ReadLine();
                            int.TryParse(temp, out inv);
                            Console.WriteLine("Please enter the price of the product.");
                            temp = Console.ReadLine();
                            decimal.TryParse(temp, out price);
                            Console.WriteLine("Please enter a Store ID to add the Product.");
                            temp = Console.ReadLine();
                            int.TryParse(temp, out id);
                            if (id == 2)
                            {
                                id = 6;
                            }
                            if (id == 3)
                            {
                                id = 11;
                            }

                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.AddProduct(dbContext, placeholder, price, inv, id);
                            }
                        }
                        else if (choice == "2")
                        {
                            Console.WriteLine("Please enter a product Name to delete");
                            temp = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.DeleteProduct(dbContext, temp);
                            }
                        }
                        else if (choice == "3")
                        {
                            string  placeholder;
                            string  old;
                            int     inv   = 1;
                            decimal price = 5.00m;
                            int     id;
                            Console.WriteLine("Please enter the old Product Name.");
                            old = Console.ReadLine();
                            Console.WriteLine("Please enter the new Product Name.");
                            placeholder = Console.ReadLine();
                            Console.WriteLine("Please enter the number of products in inventory.");
                            temp = Console.ReadLine();
                            int.TryParse(temp, out inv);
                            Console.WriteLine("Please enter the price of the product.");
                            temp = Console.ReadLine();
                            decimal.TryParse(temp, out price);
                            Console.WriteLine("Please enter a Store ID to add the Product.");
                            temp = Console.ReadLine();
                            int.TryParse(temp, out id);


                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.UpdateProduct(dbContext, placeholder, price, inv, id, old);
                            }
                        }

                        else
                        {
                            throw new ArgumentException("Please pick a valid option. ");
                        }
                    }
                    else if (choice == "4")
                    {
                        choice = "11";
                        Console.WriteLine("1: Show All Products");
                        Console.WriteLine("2: Show A Product");
                        choice = Console.ReadLine();
                        Console.Clear();
                        if (choice == "1")
                        {
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.ShowProducts(dbContext);
                                Console.ReadKey();
                            }
                        }
                        else if (choice == "2")
                        {
                            Console.WriteLine("Please enter the product name. ");
                            temp = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.ShowProducts(dbContext, temp);
                                Console.ReadKey();
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Please pick a valid option. ");
                        }
                    }
                    else if (choice == "5")
                    {
                        choice = "11";
                        Console.WriteLine("1: Add a Customer");
                        Console.WriteLine("2: Delete a Customer");
                        Console.WriteLine("3: Update a Customer");
                        choice = Console.ReadLine();
                        Console.Clear();
                        if (choice == "1")
                        {
                            string email;
                            string id;
                            Console.WriteLine("Please enter the name of the customer. ");
                            temp = Console.ReadLine();
                            Console.WriteLine("Please enter the customers email. ");
                            email = Console.ReadLine();
                            Console.WriteLine("Please enter the customers store name. ");
                            id = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.AddCustomer(dbContext, temp, email, id);
                            }
                        }
                        else if (choice == "2")
                        {
                            string email;
                            Console.WriteLine("Please enter the name of the customer. ");
                            temp = Console.ReadLine();
                            Console.WriteLine("Please enter the customers email. ");
                            email = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.DeleteCustomer(dbContext, temp, email);
                            }
                        }
                        else if (choice == "3")
                        {
                            string email, oldn, olde;
                            Console.WriteLine("Please enter the name of the customer to edit. ");
                            oldn = Console.ReadLine();
                            Console.WriteLine("Please enter the old customers email. ");
                            olde = Console.ReadLine();
                            Console.WriteLine("Please enter the new name of the customer. ");
                            temp = Console.ReadLine();
                            Console.WriteLine("Please enter the new customers email. ");
                            email = Console.ReadLine();
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.UpdateCustomer(dbContext, temp, email, oldn, olde);
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Please pick a valid option. ");
                        }
                    }
                    else if (choice == "6")
                    {
                        Console.Clear();
                        using (var dbContext = new Project0Context(options))
                        {
                            Repo.ShowCustomers(dbContext);
                            Console.ReadKey();
                        }
                    }
                    else if (choice == "7")
                    {
                        choice = "11";
                        Console.WriteLine("1: Add a product to your cart");
                        Console.WriteLine("2: Delete a product from your cart");
                        Console.WriteLine("3: Checkout");
                        choice = Console.ReadLine();
                        Console.Clear();
                        if (choice == "1")
                        {
                            int    inv = 1;
                            string name;
                            Console.WriteLine("Please enter the name of the product you'd like to add. ");
                            name = Console.ReadLine();
                            Console.WriteLine("How many would you like to add. ");
                            temp = Console.ReadLine();
                            int.TryParse(temp, out inv);
                            using (var dbContext = new Project0Context(options))
                            {
                                if (name.Substring(name.Length - 4, 3) == "Set")
                                {
                                    Repo.AddSet(dbContext, name, inv, curr_cart);
                                }
                                else
                                {
                                    Repo.AddCart(dbContext, name, inv, curr_cart);
                                }
                            }
                        }
                        else if (choice == "2")
                        {
                            int inv = 1;
                            Console.WriteLine("Please enter the name of the product you'd like to remove. ");
                            temp = Console.ReadLine();
                            Console.WriteLine("How many would you like to remove. ");
                            string temper = Console.ReadLine();
                            int.TryParse(temper, out inv);
                            using (var dbContext = new Project0Context(options))
                            {
                                Repo.DeleteCart(dbContext, temp, inv, curr_cart);
                            }
                        }
                        else if (choice == "3")
                        {
                            Console.Clear();
                            decimal total = 0;

                            using (var dbContext = new Project0Context(options))
                            {
                                if (Repo.CheckCartTime(dbContext, curr_name, curr_cart, newt))
                                {
                                    var ordertotal = dbContext.Orders.First(x => x.OrdersId == curr_cart);
                                    Repo.CheckOut(dbContext, curr_name, curr_cart, out total);
                                    Console.WriteLine("Total: " + total);
                                    Console.WriteLine("Thank you for shopping with us come back soon. ");
                                    ordertotal.Total = total;
                                    Console.ReadKey();
                                    break;
                                }
                                else
                                {
                                    Console.WriteLine("Cannot checkout at this time.");
                                    Console.ReadKey();
                                }
                            }
                        }
                        else
                        {
                            throw new ArgumentException("Please pick a valid option. ");
                        }
                    }
                    else if (choice == "8")
                    {
                        Console.Clear();
                        using (var dbContext = new Project0Context(options))
                        {
                            Repo.ShowCart(dbContext, curr_name, curr_cart);
                            Console.WriteLine("Please press any key to return. ");
                            Console.ReadKey();
                        }
                    }
                    else if (choice == "9")
                    {
                        choice = "11";
                        Console.WriteLine("1: Sort by earliest");
                        Console.WriteLine("2: Sort by latest");
                        Console.WriteLine("3: Sort by cheapest");
                        Console.WriteLine("4: Sort by most expensive");
                        Console.WriteLine("5: Show Order Statistics.");
                        choice = Console.ReadLine();
                        Console.Clear();

                        using (var dbContext = new Project0Context(options))
                        {
                            if (choice == "1" || choice == "2" || choice == "3" || choice == "4")
                            {
                                Repo.ShowHistory(dbContext, curr_name, choice);
                                Console.ReadKey();
                            }
                            else if (choice == "5")
                            {
                                Repo.ShowStatistics(dbContext);
                                Console.ReadKey();
                            }
                            else
                            {
                                Console.WriteLine("Please only enter a valid option ");
                            }
                        }
                    }
                    else
                    {
                        throw new ArgumentException("Please pick a valid option. ");
                    }
                }
                catch (ArgumentException e)
                {
                    Console.Clear();
                    Console.WriteLine(e);
                    Console.ReadKey();
                }


                choice = "11";
            }
        }
示例#9
0
 /// <summary>
 /// constructor for the project0 database access
 /// </summary>
 /// <param name="context">Dbcontext for accessing the database</param>
 public DataBase(Project0Context context)
 {
     _context = context ?? throw new ArgumentNullException(nameof(context));
 }
示例#10
0
 public LocationRepository(Project0Context context)
 {
     _context = context;
 }
示例#11
0
 protected Repository(Project0Context context)
 {
     mContext = context;
 }
示例#12
0
 /// <summary>
 /// Get the list of customers from DB and returns the number
 /// </summary>
 /// <returns>The Number of customers currently in the db</returns>
 public int NumberOfCustomers()
 {
     // set up context
     using var context = new Project0Context(_dbContext);
     return(context.Customers.ToList().Count());
 }
示例#13
0
 /// <summary>
 /// check to see if the first and last name given is an actual customer
 /// </summary>
 /// <param name="firstName">Customer First Name to check for</param>
 /// <param name="lastName">Customer last name to check for</param>
 /// <returns>True if customer with name exists, False otherwise</returns>
 public bool IsCustomer(string firstName, string lastName)
 {
     // set up context
     using var context = new Project0Context(_dbContext);
     return(context.Customers.Any(c => c.FirstName == firstName && c.LastName == lastName));
 }
示例#14
0
 /// <summary>
 /// check to see if the id given is an actual customer
 /// </summary>
 /// <param name="id">The id we want to check</param>
 /// <returns>True if customer exists, False otherwise</returns>
 public bool IsCustomer(int id)
 {
     // set up context
     using var context = new Project0Context(_dbContext);
     return(context.Customers.Any(c => c.Id == id));
 }
示例#15
0
 static Customer GetCustomerById(int id)
 {
     using var context = new Project0Context(s_dbContextOptions);
     return(context.Customers.First(x => x.Id == id));
 }
示例#16
0
 public virtual Customer FindById(int id)
 {
     using var context = new Project0Context(mOptions);
     return(context.Customer.Where(c => c.Id == id).FirstOrDefault());
 }
示例#17
0
 static Customer GetCustomerByEmail(string s)
 {
     using var context = new Project0Context(s_dbContextOptions);
     return(context.Customers.First(x => x.Email == s));
 }
示例#18
0
 public void DeleteCustomer(Customer customer)
 {
     using var context = new Project0Context(mOptions);
     context.Customer.Remove(customer);
 }
 public StoreRepository(ILogger <StoreRepository> logger,
                        Project0Context context) : base(context)
 {
     mLogger = logger;
 }
 public CustomerOrder FindById(int id)
 {
     using var context = new Project0Context(mOptions);
     return(context.CustomerOrder.Where(o => o.Id == id).FirstOrDefault());
 }
示例#21
0
        static void Main(string[] args)
        {
            Console.WriteLine("Order Games");
            var optionsBuilder = new DbContextOptionsBuilder <Project0Context>();

            optionsBuilder.UseSqlServer(SecretConfiguration.ConnectionString);
            optionsBuilder.UseLoggerFactory(AppLoggerFactory);
            var options = optionsBuilder.Options;

            var dbContext = new Project0Context(options);
            IOrdersRepository   OrdersRepository   = new OrderRepository(dbContext);
            IStoreRepository    StoreRepository    = new StoreRepository(dbContext);
            ICustomerRepository CustomerRepository = new CustomerRepository(dbContext);
            IGamesRepository    GamesRepository    = new GamesRepository(dbContext);

            //Display customer screen and select customer, then pass that customer onto the selected store
            //CustomerScreen(CustomerRepository);
            int    customerSelection    = 0;
            int    customerOptionSelect = 0;
            string name           = "";
            bool   moreGamesToBuy = true;
            //Display select store screen, or go back to customer selection
            //StoreScreen(StoreRepository);
            int storeSelection;

CustomerSelect:
            storeSelection = StoreRepository.GetStores().ToList().Count + 1;

            Console.WriteLine();
            Console.WriteLine("Press 1 to view all customers.  \nPress 2 to search for a customer by name.");
            Console.WriteLine($"Press 3 to view statistics.");

            customerOptionSelect = Convert.ToInt32(Console.ReadLine());

            if (customerOptionSelect == 1)
            {
                CustomerScreen(CustomerRepository);
                customerSelection = Convert.ToInt32(Console.ReadLine());
                if (!CustomerRepository.IsValidId(customerSelection))
                {
                    Console.WriteLine("Please input a valid customer ID");
                    goto CustomerSelect;
                }
            }
            else if (customerOptionSelect == 2)
            {
                Console.WriteLine();
                Console.WriteLine("Enter a full name: ");
                name = Console.ReadLine();
                //storeSelection = StoreRepository.GetStores().ToList().Count + 2;
            }
            else if (customerOptionSelect == 3)
            {
                int popId = OrdersRepository.GetMostPopularGame();
                Console.WriteLine();
                Console.WriteLine($"The most popular game is {GamesRepository.GetGameById(popId)}");
                goto CustomerSelect;
            }
            else
            {
                Console.WriteLine("Please enter a valid input.");
                goto CustomerSelect;
            }

            StoreScreen(StoreRepository);
            storeSelection = Convert.ToInt32(Console.ReadLine());

            CustomerImp        selectedCustomer;
            StoreImp           selectedStore;// = StoreRepository.GetStoreByLocation(storeSelection);
            List <CustomerImp> ListOfCustomers = CustomerRepository.GetCustomers().ToList();

            if (customerOptionSelect == 1)
            {
                selectedCustomer = CustomerRepository.GetCustomerById(customerSelection); //Get the chosen customer by ID
            }
            else if (customerOptionSelect == 2)
            {
                selectedCustomer = CustomerRepository.GetCustomerByName(name); //Get the chosen customer by name
            }
            else
            {
                goto CustomerSelect;
            }

            if (storeSelection == StoreRepository.GetStores().ToList().Count + 2) //if user chooses to view all order by selected cust
            {
                if (selectedCustomer.OrdersByCustomer.Count < 1)                  //if there are no orders on file for customer, go to cust select
                {
                    Console.WriteLine("Customer has no orders on file.");
                    goto CustomerSelect;
                }
                List <OrderImp> OrdersByCustomer = OrdersRepository.GetAllOrdersByCustomer(selectedCustomer.Id).ToList();
                for (int i = 0; i < selectedCustomer.OrdersByCustomer.Count; i++) //views all orders by customer
                {
                    ViewOrderDetails(OrdersByCustomer[i], StoreRepository);
                }
                Console.WriteLine("Press 1 to return to customer select.\nPress 2 to view list of stores.");
                int temp = Convert.ToInt32(Console.ReadLine());
                if (temp == 1)
                {
                    goto CustomerSelect;
                }
                else if (temp == 2)
                {
                    StoreScreen(StoreRepository);
                    storeSelection = Convert.ToInt32(Console.ReadLine());
                    goto StoreSelect;
                }
                else
                {
                    Console.WriteLine("Invalid input, redirecting to customer select.");
                    goto CustomerSelect;
                }
            }
            else if (storeSelection == StoreRepository.GetStores().ToList().Count + 1)
            {
                goto CustomerSelect;
            }

StoreSelect:
            selectedStore = StoreRepository.GetStoreByLocation(storeSelection); //Get the chosen store

OptionSelect:
            OptionsScreen(); //View options to handle or add orders
            int optionSelect = Convert.ToInt32(Console.ReadLine());
            int gameSelect   = 0;
            int viewSelect   = 0;

            if (optionSelect == 1) //view all orders at this store
            {
ViewSelect:
                ViewOrdersScreen();
                viewSelect = Convert.ToInt32(Console.ReadLine());
                if (viewSelect == 1)
                {
                    List <OrderImp> OrderList = OrdersRepository.GetOrderByDate(selectedStore).ToList();
                    if (OrderList.Count < 1)
                    {
                        Console.WriteLine();
                        Console.WriteLine("There are no orders at this store.");
                        goto OptionSelect;
                    }
                    ViewAllOrdersInList(OrderList, StoreRepository);
                }
                else if (viewSelect == 2)
                {
                    List <OrderImp> OrderList = OrdersRepository.GetOrderByDateReverse(selectedStore).ToList();
                    if (OrderList.Count < 1)
                    {
                        Console.WriteLine();
                        Console.WriteLine("There are no orders at this store.");
                        goto OptionSelect;
                    }
                    ViewAllOrdersInList(OrderList, StoreRepository);
                }
                else if (viewSelect == 3)
                {
                    List <OrderImp> OrderList = OrdersRepository.GetOrderByCost(selectedStore).ToList();
                    if (OrderList.Count < 1)
                    {
                        Console.WriteLine();
                        Console.WriteLine("There are no orders at this store.");
                        goto OptionSelect;
                    }
                    ViewAllOrdersInList(OrderList, StoreRepository);
                }
                else if (viewSelect == 4)
                {
                    List <OrderImp> OrderList = OrdersRepository.GetOrderByCostReverse(selectedStore).ToList();
                    if (OrderList.Count < 1)
                    {
                        Console.WriteLine();
                        Console.WriteLine("There are no orders at this store.");
                        goto OptionSelect;
                    }
                    ViewAllOrdersInList(OrderList, StoreRepository);
                }
                else if (viewSelect == 5)
                {
                    goto OptionSelect;
                }
                else
                {
                    Console.WriteLine("Please enter a valid input.");
                    goto ViewSelect;
                }
            }
            else if (optionSelect == 2) //Place an order at selected store
            {
                if (!selectedStore.CheckIfOrderIsReady(selectedCustomer))
                {
                    Console.WriteLine();
                    Console.WriteLine($"You have ordered from this story within the last 2 hours, " +
                                      $"please pick a different option");
                    goto OptionSelect;
                }
                OrderImp      newOrder = new OrderImp();
                OrderGamesImp newGames;
                while (moreGamesToBuy)
                {
                    newGames = new OrderGamesImp();
GameSelection:
                    PlaceOrderScreen(GamesRepository, selectedCustomer);
                    gameSelect = Convert.ToInt32(Console.ReadLine());

                    if (GamesRepository.GetGameById(gameSelect) == null)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Please enter valid ID number");
                        goto GameSelection;
                    }

                    GamesImp selectedGame = GamesRepository.GetGameById(gameSelect);
                    selectedCustomer.LastGameBoughtId = selectedGame.Id;

EditionSelect:
                    Console.WriteLine();
                    Console.WriteLine("Enter the game edition: ");
                    Console.WriteLine($"1. Standard edition: {selectedGame.Cost}");
                    Console.WriteLine($"2. Advanced edition: {selectedGame.AdvancedCost}");
                    Console.WriteLine($"3. Deluxe edition: {selectedGame.AdvancedCost + 10}");
                    int selectedEdition = Convert.ToInt32(Console.ReadLine());

                    if (selectedEdition != 1 && selectedEdition != 2 && selectedEdition != 3)
                    {
                        Console.WriteLine("Please enter a valid edition number.");
                        goto GameSelection;
                    }
                    string editionName = "";
                    if (selectedEdition == 1)
                    {
                        editionName = "Standard";
                    }
                    else if (selectedEdition == 2)
                    {
                        editionName = "Advanced";
                    }
                    else
                    {
                        editionName = "Deluxe";
                    }
                    Console.WriteLine();
                    Console.WriteLine($"Enter the number of {selectedGame.Name}, {editionName} Edition");
                    int quantityOfGame = Convert.ToInt32(Console.ReadLine());

                    StoreRepository.RemoveFromStock(quantityOfGame, selectedGame, selectedStore);
                    if (editionName == "Deluxe")
                    {
                        if (selectedStore.DeluxeInStock < quantityOfGame)
                        {
                            Console.WriteLine("Not enough deluxe in stock, choose another edition.");
                            goto EditionSelect;
                        }
                        else
                        {
                            StoreRepository.RemoveDeluxeFromStock(quantityOfGame, selectedStore.IDNumber);
                        }
                    }

                    //Assign the game purchases' statistics
                    newGames.Game         = selectedGame;
                    newGames.GameId       = selectedGame.Id;
                    newGames.Edition      = selectedEdition;
                    newGames.GameQuantity = quantityOfGame;
                    newGames.OrderId      = 100;

                    newOrder.GamesInOrder.Add(newGames);

AddGameChoice:
                    Console.WriteLine("Do you want to add another game?\nPress 1 to add another game\nPress 2 to finish order.");
                    int nextAction = Convert.ToInt32(Console.ReadLine());
                    if (nextAction == 1)
                    {
                    }
                    else if (nextAction == 2)
                    {
                        moreGamesToBuy = false;
                    }
                    else
                    {
                        Console.WriteLine("Enter a valid input.");
                        goto AddGameChoice;
                    }


                    //OrderImp newOrder = new OrderImp(DateTime.Now, selectedCustomer.Id, selectedStore.ShippingCosts, selectedStore);
                }
                newOrder.OrderDate     = DateTime.Now;
                newOrder.OrderCustomer = selectedCustomer.Id;
                newOrder.StoreId       = selectedStore.IDNumber;
                OrdersRepository.AddOrder(newOrder);                  //Adds the new order to database
                Console.WriteLine("newOrder's OrderId = " + newOrder.OrderID);
                for (int i = 0; i < newOrder.GamesInOrder.Count; i++) //adds all new OrderGames to database and assigns their OrderId
                {
                    newOrder.GamesInOrder[i].OrderId = OrdersRepository.GetExactOrderByDate(newOrder.OrderDate).OrderID;
                    OrdersRepository.AddOrderItem(newOrder.GamesInOrder[i]);
                }
            }
            else if (optionSelect == 3) //go back to store selection screen
            {
                StoreScreen(StoreRepository);
                storeSelection = Convert.ToInt32(Console.ReadLine());
                goto StoreSelect;
            }
            else //invalid input
            {
                Console.WriteLine("Please enter a valid input.");
                goto OptionSelect;
            }

            FinalMenu();
            int input = Convert.ToInt32(Console.ReadLine());

            switch (input)
            {
            case 1:
                StoreScreen(StoreRepository);
                storeSelection = Convert.ToInt32(Console.ReadLine());
                goto StoreSelect;

            case 2:
                goto CustomerSelect;

            default:
                break;
            }



            Console.ReadLine();
        }
示例#22
0
 public CustomerOrderRepository(ILogger <CustomerOrderRepository> logger,
                                Project0Context context) : base(context)
 {
     mLogger = logger;
 }
示例#23
0
        static void Main(string[] args)
        {
            ////For the debugging the code for SQL
            using var logStream = new StreamWriter("ef-logs.txt");
            //// DbContextOptions is how we give the context its connection string (to log in to the sql server),
            //// tell it to use SQL server
            var optionsBuilder = new DbContextOptionsBuilder <Project0Context>();

            optionsBuilder.UseSqlServer(GetConnectionString());
            optionsBuilder.LogTo(logStream.Write, LogLevel.Information);
            using var context = new Project0Context(optionsBuilder.Options);


            StoreRepository storeRepo = new StoreRepository(context);

            int action = chooseAction();

            while (action != 0)
            {
                var random = new Random();
                Console.WriteLine("You chose " + action);
                switch (action)
                {
                //place an order
                case 2:
                    Console.WriteLine("let's place an order");
                    int    Id      = random.Next(1, 1000);
                    int    OrderId = random.Next(1, 1000);
                    string ProductId;
                    int    PID;
                    string Pr;
                    int    Price;
                    string Qua;
                    int    Quantity;
                    Console.WriteLine("Enter the Product Id");
                    ProductId = Console.ReadLine();
                    Console.WriteLine("Enter the Price");
                    Pr = Console.ReadLine();
                    Console.WriteLine("Enter the Quantity");
                    Qua      = Console.ReadLine();
                    PID      = Convert.ToInt32(ProductId);
                    Price    = Convert.ToInt32(Pr);
                    Quantity = Convert.ToInt32(Qua);
                    var newSales = new Library.Sale(Id, OrderId, PID, Price, Quantity);
                    storeRepo.AddSales(newSales);


                    break;

                // add a new customer
                case 1:
                    Console.WriteLine("Let's add a new customer");
                    string Name       = "";
                    int    CustomerId = random.Next(1, 10000);
                    Console.WriteLine("Enter the name");
                    Name = Console.ReadLine();

                    var newCustomer = new Library.Customer(CustomerId, Name);
                    storeRepo.AddCustomer(newCustomer);
                    Console.WriteLine(Name + " was added");
                    break;

                // Search Customer by Name
                case 6:
                    Console.WriteLine("Let's Search for a customer");
                    string SName = "";
                    Console.WriteLine("Enter the name");
                    SName = Console.ReadLine();

                    var oldCustomer = new Library.Customer(SName);
                    //storeRepo.SearchCustomers(oldCustomer);

                    break;

                // Display Details of An Order
                case 3:
                    break;

                // Display Order History of a Store
                case 4:
                    break;

                // Display Order History of a Customer
                case 5:
                    break;

                default:
                    break;
                }
                action = chooseAction();
            }
        }
示例#24
0
        /**************************************
        * PRODUCT FUNCTIONS BELOW
        * ************************************/

        /*       public static void AddProduct(Product product)
         *     {
         *         //remember to save.
         *         Products prods = Mapper.MapProduct();
         *     }*/

        ///<summary>
        ///This option not required at this time
        ///</summary>
        //public static int AddProduct(Products product)
        //{
        //    using (var db = new Project0Context())
        //    {
        //        Console.WriteLine("Inserting a new product");
        //        db.Add(product);
        //        //db.Add(new Products
        //        //{
        //        //    ProductName = "mango",
        //        //    ProductPrice = 1234
        //        //});
        //        db.SaveChanges();
        //        //products.Add(product);
        //        return 1;
        //    }
        //}

        ///<summary>
        ///This option not required at this time
        ///</summary>
        //public static Products ReadProduct(Products product)
        //{
        //    //find the product in the array
        //    using (var db = new Project0Context())
        //    {
        //        Console.WriteLine("Reading a product");
        //        var prod = db.Products.Find(2);
        //        return prod;
        //    }
        //}

        ///<summary>
        ///returns a list of all the Products
        ///</summary>
        ///
        public static List <Products> ReadAllProducts(Project0Context context)
        {
            return(context.Products.ToList());
        }
示例#25
0
 /// <summary>
 /// The product object
 /// </summary>
 /// <remarks>
 /// Returns the database model so we don't have to convert back and forth
 /// </remarks>
 /// <param name="name">Name of product</param>
 /// <returns>Database Product</returns>
 public DatabaseModels.Product GetProduct(string name)
 {
     // get the context of the db
     using var context = new Project0Context(_dbContext);
     return(context.Products.FirstOrDefault(p => p.Name == name));
 }
示例#26
0
        ///<summary>
        ///This option not required at this time
        ///</summary>
        //public static List<Product> UpdateProduct(Project0Context context, Product product)
        //{
        //    //find then update the product
        //    return products;
        //}

        ///<summary>
        ///This option not required at this time
        ///</summary>
        //public static List<Product> DeleteProduct(List<Product> products, Product product)
        //{
        //    return products;
        //}


        ///<summary>
        ///This option not required at this time
        ///</summary>
        //public static Product SearchProducts(Product product)
        //{
        //    return product;
        //}

        /**************************************
         * LOCATION FUNCTIONS BELOW
         * *************************************/

        //public static int AddLocation(Location location)
        //{
        //    using (var db = new Project0Context())
        //    {
        //        Console.WriteLine("Inserting a new product");
        //        db.Add(location);
        //        //db.Add(new Products
        //        //{
        //        //    ProductName = "apple",
        //        //    ProductPrice = 1234
        //        //});
        //        db.SaveChanges();
        //        //products.Add(product);
        //        return 1;
        //        //locations.Add(location);
        //        //return locations;
        //    }
        //}

        ///<summary>
        ///takes a context and returns a List of Locations
        ///</summary>
        public static List <Locations> ReadAllLocations(Project0Context db)
        {
            return(db.Locations.ToList());
        }
示例#27
0
 public StoreRepository(Project0Context db)
 {
     _db = db ?? throw new ArgumentNullException(nameof(db));
 }
示例#28
0
 ///<summary>
 ///this takes a DB context and returns a List of all orders
 ///</summary>
 public static List <Orders> ReadAllOrders(Project0Context context)
 {
     return(context.Orders.ToList());
 }
示例#29
0
        }//END OF SignInUser()

        static void Main(string[] args)
        {
            bool finished       = false;
            var  optionsBuilder = new DbContextOptionsBuilder <Project0Context>();

            optionsBuilder.UseSqlServer(config.connectionString);
            using (var db = new Project0Context(optionsBuilder.Options))
            {
                Customer customer = new Customer();
                Order    order    = new Order();
                Location location = new Location();

                while (finished.Equals(false))
                {
                    /*******************log in or register the user*******************/
                    string userType;
                    do
                    {
                        Console.WriteLine("Are you a returning user of do you need to register?");
                        Console.WriteLine("\n\n\tA - Register.\n\tB - Returning User.");
                        userType = Console.ReadLine();
                        userType = userType.ToUpper();  //to accept upper and lower case letters.
                    } while (!(userType.Equals("A") || userType.Equals("B")));

                    switch (userType)
                    {
                    case "A":
                        bool custExists = false;
                        while (custExists == false)
                        {
                            customer   = RegisterUser();         //register the user
                            custExists = DBRepository.AddCustomer(db, customer);
                            //add the new, VALIDATED, user to the DB.
                        }
                        break;

                    case "B":
                        string custExists2 = null;
                        while (custExists2 == null)
                        {
                            customer = SignInUser(db);     //sign the user in.
                            customer = DBRepository.ReadCustomer(db, customer);
                            if (customer != null)
                            {
                                custExists2 = "good";
                            }
                        }
                        break;
                    }

                    /***************************CHOOSE TO SEARCH OR PLACE AN ORDER***********************/
                    bool quitter1 = false;
                    do
                    {
                        do
                        {
                            Console.WriteLine("\n Would you like to continue to the ordering process, " +
                                              "or would you like to search for things??");
                            Console.WriteLine("\n\n\tA - Proceed to order.\n\tB - Search.");
                            userType = Console.ReadLine();
                            userType = userType.ToUpper();  //to accept upper and lower case letters.
                        } while (!(userType.Equals("A") || userType.Equals("B")));

                        switch (userType)
                        {
                        case "A":
                            Console.WriteLine("\n\t.......Proceeding to the ordering page.......");
                            quitter1 = true;
                            break;

                        case "B":
                            searching.goSearching(db);
                            break;
                        }
                        if (quitter1 == true)
                        {
                            break;
                        }

                        Console.WriteLine("Would you like to START OVER or QUIT?\n\t\tType START OVER or QUIT");
                        string answer = Console.ReadLine();
                        answer = answer.ToLower();
                        if (answer.Equals("start over"))
                        {
                            //continue;
                        }
                        else
                        {
                            quitter1 = true;
                            System.Environment.Exit(0);
                        }
                    } while (quitter1 == false);



                    /**********************choose the location*****/
                    var    allLocations = DBRepository.ReadAllLocations(db);//returns a list of locations
                    string locChoice;
                    int    finalLocChoice;
                    do
                    {
                        foreach (var item in allLocations)
                        {
                            Console.WriteLine($"{item.LocationId} - {item.LocationName}\n");
                        }
                        Console.WriteLine("Please choose a number from the above list.");
                        locChoice      = Console.ReadLine();
                        finalLocChoice = Convert.ToInt32(locChoice);
                        location       = DBRepository.ReadLocationById(db, finalLocChoice);
                    } while (location == null);

                    Console.WriteLine($"You chose our {location.LocationName} location. Happy shopping!");


                    /*************************Make the order****************************/
                    //int prodChoice;
                    string choice;
                    string choiceQuantity;
                    int    choiceQuantityInt;
                    //get all the products in the chosen locations inventory
                    var allProductsInInventory = DBRepository.ReadLocationInventory(db, location.LocationName);

                    var allProducts = DBRepository.ReadAllProducts(db);


                    do
                    {
                        Console.WriteLine("\n\tPlease choose from the available product numbers.\n\tEnter a product number and hit enter." +
                                          "\n\tYou may keep placing products until\n\tyou enter 'checkout' to check out.");

                        //display all products from this location.
                        foreach (var item in allProductsInInventory)
                        {
                            int     testNum = item.ProductId;
                            Product prod    = DBRepository.ReadProductById(db, item.ProductId);
                            //Console.WriteLine($"this is item.ProductID=>{item.ProductId} ... This is testNum=>{testNum} ...this is prod.ProductID=>{prod.ProductID}");
                            Console.WriteLine($"\t{prod.ProductID} - {prod.ProductName} = {prod.ProductPrice}. {item.ProductQuantity} in stock.");
                        }
                        Console.WriteLine("\tcheckout - Check out.");
                        choice = Console.ReadLine();
                        choice = choice.ToLower();
                        if (choice.Equals("checkout"))
                        {
                            continue;
                        }
                        int prodIdChoice;
                        prodIdChoice = Convert.ToInt32(choice);

                        //make sure the name entered is in the list.
                        if (allProductsInInventory.Exists(x => x.ProductId == prodIdChoice) == false)
                        {
                            Console.WriteLine("\n\t\tYour choice is not in the list.");
                            continue;
                        }
                        else
                        {
                            //get the chosen named Product from the Products table.
                            Inventory choice3 = allProductsInInventory.Find(x => x.ProductId.Equals(prodIdChoice));
                            Product   prod    = DBRepository.ReadProductById(db, choice3.ProductId);


                            Console.WriteLine($"\nHow Many {prod.ProductName}'s would you like? There are {choice3.ProductQuantity} available");

                            //Console.WriteLine($"found product => {choice3.ProductName} - {choice3.ProductPrice} - {choice3.ProductQuantity}");
                            choiceQuantity    = Console.ReadLine();
                            choiceQuantityInt = Convert.ToInt32(choiceQuantity);

                            if (choiceQuantityInt > choice3.ProductQuantity)
                            {
                                Console.WriteLine($"\nThere are not enough {prod.ProductName} available. \nThe maximum you may add is {choice3.ProductQuantity}. Try again.\n");
                                continue;
                            }
                            else
                            {
                                //check if the item has already been ordered. if not, add it and decrement amount available.
                                if (order.itemsOrdered.ContainsKey(prod.ProductName) == false)
                                {
                                    order.itemsOrdered.Add(prod.ProductName, choiceQuantityInt);
                                    choice3.ProductQuantity -= choiceQuantityInt;//decrement amount in context
                                }
                                else
                                {
                                    //add the previously ordered quantity back to the inventory then subtract the newly ordered amount
                                    choice3.ProductQuantity = choice3.ProductQuantity + order.itemsOrdered[prod.ProductName];
                                    order.itemsOrdered[prod.ProductName] = choiceQuantityInt;
                                    choice3.ProductQuantity = choice3.ProductQuantity - choiceQuantityInt;//decrement amount in context
                                    Console.WriteLine($"\n\tYour desired amount of {prod.ProductName} has been updated to {order.itemsOrdered[prod.ProductName]}");
                                }
                            }
                        }
                        //print current state of customers order
                        Console.WriteLine("\nYou current order is... ");
                        foreach (var item in order.itemsOrdered)
                        {
                            Console.WriteLine($"=== {item.Key} === {item.Value}=");
                        }
                    } while (!choice.Equals("checkout"));//end of ordering loop
                    order.LocationID = location.locID;
                    order.CustomerID = customer.CustID;
                    DBRepository.AddOrder(db, order);
                    db.SaveChanges();

                    finished = true;
                } //END OF WHILE LOOP
                Console.WriteLine("\n\n\t============= Thank You for shopping with us. =============\n");
            }     //END OF USING
        }         //END OF MAIN
 public StoreRepository(Project0Context context)
 {
     _dbContext = context ?? throw new ArgumentNullException("Null Context.");
 }