Ejemplo n.º 1
0
/// <summary>
/// This method, AddCustomer, is used to gather a users first and last name as well as a username.
/// the username is then associated with the primary key of the customer table of the database
/// This is for first time users only.
/// </summary>
        public static string AddCustomer()
        {
            System.Console.WriteLine("Please enter your first name: ");
            string firstName = Console.ReadLine();

            System.Console.WriteLine("Please enter your last name: ");
            string lastName = Console.ReadLine();

            System.Console.WriteLine("Please enter a username: ");
            string userName = Console.ReadLine();

            using (var context = new Flowers.ConsoleApp.Entities.FlowersContext())
            {
                var newCustomer = new Flowers.ConsoleApp.Entities.Customer {
                    FirstName = firstName,
                    LastName  = lastName,
                    Username  = userName
                };

                context.Customer.Add(newCustomer);
                context.SaveChanges();
            }
            return(userName);
        }
Ejemplo n.º 2
0
/// <summary>
/// In this method called AddOrder, you can see that there is a "currentuser" string. This is associated
/// with the user's CustomerID, which is the primary key value associated with their username.
/// it allows the user to select a store to order from, then select any number or kind of flowers to order in a cart,
///  and then it adds up the total and displays the price to the user.
/// Also includes order time.
/// In addition, it decrements products from the inventory when an order is placed.
///
/// </summary>

        public static void AddOrder(string currentuser)
        {
            Console.WriteLine("What store would you like to purchase from?");
            Console.WriteLine("Please select a location: ");
            Console.WriteLine("1. Texas");
            Console.WriteLine("2. New York");
            var storechoice = int.Parse(Console.ReadLine());

            bool done = false;
            Dictionary <string, double> cart = new Dictionary <string, double>();
            double price  = 0;
            string flower = "";

            while (!done)
            {
                Console.WriteLine("What would you like to purchase?");
                Console.WriteLine("Please select what flower you would like: ");
                Console.WriteLine("1. Rose");

                Console.WriteLine("2. Daisy");

                Console.WriteLine("3. Sunflower");

                Console.WriteLine("4. Daffodil");

                Console.WriteLine("5. Tulip");

                Console.WriteLine("6. Lily");

                var flowerchoice = int.Parse(Console.ReadLine());

                using (var context = new Flowers.ConsoleApp.Entities.FlowersContext())
                {
                    var row = new Product();

                    while (row.ProductName == null)
                    {
                        try
                        {
                            row    = context.Product.First(p => p.ProductId == flowerchoice);
                            price  = Convert.ToDouble(row.ProductPrice);
                            flower = row.ProductName;

                            Console.WriteLine("Thank you for purchasing a " + row.ProductName);
                            Console.ReadLine();
                            // here we need to decrement the inventory count as well as add a new order to the orders table with appropriate data
                            var inventoryobject = context.Inventory.First(c => c.ProductId == flowerchoice);
                            inventoryobject.InventoryCount = inventoryobject.InventoryCount - 1;
                            context.Update(inventoryobject);
                            context.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex);
                            Console.WriteLine("Invalid input");
                            break;
                        }
                    }
                };

                cart.Add(flower, price);
                Console.WriteLine("Would you like to purchase another flower? y/n");
                string moreflower = Console.ReadLine();
                if (moreflower != "y")
                {
                    done = true;
                }
            }

            DateTime now = DateTime.Now;

            using (var context = new Flowers.ConsoleApp.Entities.FlowersContext())
            {
                double total = 0;
                foreach (var item in cart)
                {
                    total = total + item.Value;
                }
                Console.WriteLine("Your total is $" + total);
                Console.ReadLine();
                var getid = context.Customer.First(g => g.Username == currentuser).CustomerId;

                var newOrder = new Order()
                {
                    StoreId    = storechoice,
                    SaleDate   = now,
                    CustomerId = getid,
                    OrderTotal = Convert.ToDecimal(total)
                };
                context.Order.Add(newOrder);
                context.SaveChanges();
            }
        }