public void GetOrdersByLocationDB(int locationID)
        {
            DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>()
                                                            .UseSqlServer(secret.ConnectionString).Options;
            var context  = new CupCakeShopContext(options);
            var context2 = new CupCakeShopContext(options);
            var context3 = new CupCakeShopContext(options);

            //Deleted the Counter Place Holder in your Cart

            foreach (Orders order in context.Orders)
            {
                var product  = context2.Product.FirstOrDefault(p => p.ProductId == order.ProductId);
                var location = context3.Location.FirstOrDefault(p => p.LocationId == order.LocationId);

                if (order.LocationId == locationID)
                {
                    Console.WriteLine("------------------------------------------------------------------------------------------");
                    Console.WriteLine($"| LocationID: {order.LocationId} | Location: {location.City} | Product: {product.Pname} | Quantity: {order.Quantity} | Date: {order.OrderTime} |");
                    Console.WriteLine("------------------------------------------------------------------------------------------");
                }
                else
                {
                    Console.WriteLine("--No data--");
                }
            }
            Console.WriteLine("\nPress a key to continue");
            Console.ReadKey();
        }
        public void GetAllLocationsDB()
        {
            DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>()
                                                            .UseSqlServer(secret.ConnectionString).Options;
            var context = new CupCakeShopContext(options);

            foreach (Location location in context.Location)     //Just display all
            {
                Console.WriteLine("----------------------------------------------");
                Console.WriteLine($"| LocationId: {location.LocationId} | City: {location.City} |");
                Console.WriteLine("----------------------------------------------");
            }
        }
        public void GetAllProducts()
        {
            DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>()
                                                            .UseSqlServer(secret.ConnectionString).Options;
            var context = new CupCakeShopContext(options);

            foreach (Product product in context.Product)                     //display all
            {
                Console.WriteLine("--------------------------------------------");
                Console.WriteLine($"| ProductId: {product.ProductId} | ProductName: {product.Pname} | Price  {product.Price} $");
                Console.WriteLine("-------------------------------------------");
            }
        }
        public void AddNewCustomerDB()
        {
            DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>()
                                                            .UseSqlServer(secret.ConnectionString).Options;
            var context = new CupCakeShopContext(options);

            Customer newCustomer = new Customer();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Cup Cake Shop\n");
                Console.WriteLine("Enter Customer First and Last Name:");
                Console.WriteLine("(or 1 to Return to Menu)\n");

                string customerName = Console.ReadLine();

                string[] fullName = customerName.Split(' ');

                if (fullName[0].ToLower() == "1")           //main menu
                {
                    return;
                }
                else if (string.IsNullOrEmpty(customerName) || fullName.Length != 2)    //validation
                {
                    Console.WriteLine("Invalid Name\n");
                    Console.WriteLine("Press a key to continue.");
                    Console.ReadKey();
                }
                else
                {
                    newCustomer.FirstName = fullName[0];            //add
                    newCustomer.LastName  = fullName[1];
                    break;
                }
            }

            context.Customer.Add(newCustomer);

            context.SaveChanges();

            Console.Clear();
            Console.WriteLine("Cup Cake Shop\n");

            Console.WriteLine($"{newCustomer.FirstName} {newCustomer.LastName} added to the system.\n");   //show output
            Console.WriteLine("Press a key to continue: ");
            Console.ReadKey();
        }
示例#5
0
        public void SearchForCustomerDB(string firstName, string lastName)
        {
            DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>()
                                                            .UseSqlServer(secret.ConnectionString).Options;
            var context = new CupCakeShopContext(options);


            var foundName = context.Customer.FirstOrDefault(p => p.FirstName == firstName && p.LastName == lastName);

            if (foundName is null)
            {
                Console.WriteLine("No Record Found");       //validation
                return;
            }
            Console.WriteLine("-------------------------------------------");
            Console.WriteLine($"\n| CustomerId: {foundName.CustomerId} | CustomerName: {foundName.FirstName} {foundName.LastName} |");
            Console.WriteLine("-------------------------------------------");
        }
示例#6
0
        public int GetCustomerIdDB(string firstName, string lastName)
        {
            DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>()
                                                            .UseSqlServer(secret.ConnectionString).Options;
            var context = new CupCakeShopContext(options);

            var foundName = context.Customer.FirstOrDefault(p => p.FirstName == firstName && p.LastName == lastName);   //find the first

            if (foundName is null)
            {
                Console.WriteLine("No Record Found");         // validate
                return(0);
            }
            else
            {
                return(foundName.CustomerId);
            }
        }
        public void PlaceNewOrderDB(int customerId, int cupId, int cupLocationId, int cupQuantId, decimal orderTotal)
        {
            DbContextOptions <CupCakeShopContext> options = new DbContextOptionsBuilder <CupCakeShopContext>()
                                                            .UseSqlServer(secret.ConnectionString).Options;
            var context = new CupCakeShopContext(options);


            Orders newOrder = new Orders();

            newOrder.CustomerId = customerId;
            newOrder.ProductId  = cupId;
            newOrder.LocationId = cupLocationId;
            newOrder.Quantity   = cupQuantId;
            newOrder.OrderTotal = orderTotal;
            DateTime now = DateTime.Now;

            newOrder.OrderTime = now;

            context.Orders.Add(newOrder);

            context.SaveChanges();
        }
示例#8
0
        public void GetOrdersByCustomerDB(int customerID)
        {
           

            DbContextOptions<CupCakeShopContext> options = new DbContextOptionsBuilder<CupCakeShopContext>()
                .UseSqlServer(secret.ConnectionString).Options;
             var context = new CupCakeShopContext(options);
             var context2 = new CupCakeShopContext(options);      //3 context for 1.Cust 2.Prod 3.Loctn
             var context3 = new CupCakeShopContext(options);

            foreach (Orders order in context.Orders)
            {
                var product = context2.Product.FirstOrDefault(p => p.ProductId == order.ProductId);
                var location = context3.Location.FirstOrDefault(p => p.LocationId == order.LocationId);

                if (order.CustomerId == customerID)
                {
                    Console.WriteLine("-------------------------------------------------------------------------------------------------------");
                    Console.WriteLine($"| CustomerId: {order.CustomerId} | Location: {location.City} | ProductName: {product.Pname} | Quantity: {order.Quantity} | Date: {order.OrderTime} |" );
                    Console.WriteLine("-------------------------------------------------------------------------------------------------------");
                }
            }
        }