示例#1
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();
            }
        }
示例#2
0
        /// <summary>
        /// creates the list of products for an order to have
        /// </summary>
        /// <remarks>
        /// The list of current products in the order is actually stored in the session.
        /// This is just an input/ouput to show and get from the user
        /// </remarks>
        public static void MakeOrder()
        {
            Console.Clear();
            if (ses.CurrentCustomer != null && ses.CurrentLocation != null)
            {
                string input = "";
                while (input != "d")
                {
                    // Clear the console
                    Console.Clear();
                    // Display products from the store selected
                    PrintLocationInventory();
                    PrintCurrentOrder(ses.GetCurrentOrderSales());
                    //ask the user for a product Id or if they are done
                    Console.Write("Type Product Id or (D)one:");
                    input = Console.ReadLine();
                    if (input.ToLower() == "d")
                    {
                        continue;
                    }

                    // parse the product number
                    int productId;
                    try
                    {
                        productId = Int32.Parse(input);
                    }
                    catch (ArgumentException)
                    {
                        Console.WriteLine("Please enter a number.");
                        WaitOnKeyPress();
                        continue;
                    }

                    // make sure the product id selected is in current list
                    if (ses.IsInLocationInventory(productId))
                    {
                        // get quantity from the user
                        Console.Write("Please enter quanity: ");
                        int quantity;
                        try
                        {
                            quantity = Int32.Parse(Console.ReadLine());
                        }
                        catch (ArgumentException)
                        {
                            Console.WriteLine("Please enter a number");
                            WaitOnKeyPress();
                            continue;
                        }
                        // ensure quantity typed is above 0 and at or below order limit
                        if (quantity > 0 && ses.IsWithinOrderLimit(productId, quantity) && ses.IsEnoughInventory(productId, quantity))
                        {
                            //create new product and add it to the list
                            var sale = new Library.Sale(productId, quantity);
                            ses.AddSaleToOrder(sale);
                        }
                        else
                        {
                            // error checking
                            if (quantity <= 0)
                            {
                                Console.WriteLine("Please Enter Value above 0.");
                            }
                            else
                            {
                                // reach here when the quantity requested is higher than the order limit or doesn't have enough inventory
                                Console.WriteLine("Please enter a valid number.");
                            }
                            WaitOnKeyPress();
                        }
                    }
                }
                // when done, check to see if there was anything added to the order
                // Don't want empty orders to be added to the db
                if (ses.GetCurrentOrderSales().Count != 0)
                {
                    ses.AddOrder();
                }
                else
                {
                    Console.WriteLine("Nothing added to order.");
                }
            }
            else
            {
                Console.WriteLine("Please select both a Customer and Location.");
            }
        }