Пример #1
0
        public void PlaceNewOrderDB(int customerId, int filmProductId, int filmLocationId, int filmQuantityId, decimal orderTotal)
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

            DateTime dateTime = new DateTime(2019, 10, 16);

            Orders newOrder = new Orders();

            newOrder.CustomerId = customerId;
            newOrder.ProductId  = filmProductId;
            newOrder.LocationId = filmLocationId;
            newOrder.Quantity   = filmQuantityId;
            newOrder.OrderTotal = orderTotal;
            newOrder.OrderTime  = dateTime;

            context.Orders.Add(newOrder);

            context.SaveChanges();
        }
        public void AddNewInventoryDB(string filmTitle, string filmPrice)
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

            var product = new Product();

            product.Title = filmTitle;
            product.Price = decimal.Parse(filmPrice);

            context.Product.Add(product);

            context.SaveChanges();

            Console.Clear();
            Console.WriteLine("Top Ten Video Store\n");
            Console.WriteLine($"{product.Title} ${product.Price} Added.\n");
            Console.WriteLine("Hit any Key to Continue: ");
            Console.ReadKey();
        }
Пример #3
0
        public void GetOrdersByLocationDB(int locationID)
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context  = new TopTenMoviesContext(options);
            using var context2 = new TopTenMoviesContext(options);
            using var context3 = new TopTenMoviesContext(options);

            int count = 0;

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

                if (order.LocationId == locationID)
                {
                    count++;

                    Console.WriteLine($"[LocationID] {order.LocationId} [Location] {location.City} [Title] {title.Title} " +
                                      $"[Quantity] {order.Quantity}");
                }
            }
            if (count == 0)
            {
                Console.WriteLine("\nNo Orders at this Location");
                Console.WriteLine("\nHit any Key to Continue");
                Console.ReadKey();
            }
        }
Пример #4
0
        public void AddNewCustomerDB()
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

            Customer newCustomer = new Customer();

            while (true)
            {
                Console.Clear();
                Console.WriteLine("Top Ten Video Store\n");
                Console.WriteLine("Enter Customer First and Last Name:");
                Console.WriteLine("(or Exit to Return to Menu)\n");

                string customerName = Console.ReadLine();

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

                if (fullName[0].ToLower() == "exit")
                {
                    return;
                }
                else if (string.IsNullOrEmpty(customerName) || fullName.Length != 2)
                {
                    Console.WriteLine("Invalid Name\n");
                    Console.WriteLine("Hit any Key to Continue.");
                    Console.ReadKey();
                }
                else
                {
                    newCustomer.FirstName = fullName[0];
                    newCustomer.LastName  = fullName[1];
                    break;
                }
            }

            context.Customer.Add(newCustomer);

            context.SaveChanges();

            Console.Clear();
            Console.WriteLine("Top Ten Video Store\n");
            Console.WriteLine($"{newCustomer.FirstName} {newCustomer.LastName} Added.\n");
            Console.WriteLine("Hit any Key to Continue: ");
            Console.ReadKey();
        }
        public void GetAllLocationsDB()
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

            foreach (Location location in context.Location)
            {
                Console.WriteLine($"[LocationId] {location.LocationId} [City] {location.City}");
            }
        }
        public void GetAllProducts()
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

            foreach (Product product in context.Product)
            {
                Console.WriteLine($"[ProductId] {product.ProductId} [Title] {product.Title}");
            }
        }
        public void GetAllCustomersDB()
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

            Console.Clear();

            foreach (Customer customer in context.Customer)
            {
                Console.WriteLine($"[CustomerId] {customer.CustomerId} [Customer Name] {customer.FirstName} {customer.LastName}");
            }
        }
        public void SearchForCustomerDB(string firstName, string lastName)
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

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

            if (foundName is null)
            {
                Console.WriteLine("No Record Found");
                return;
            }

            Console.WriteLine($"\n[CustomerId] {foundName.CustomerId} [Customer Name] {foundName.FirstName} {foundName.LastName}");
        }
Пример #9
0
        public int GetCustomerIdDB(string firstName, string lastName)
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context = new TopTenMoviesContext(options);

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

            if (foundName is null)
            {
                Console.WriteLine("No Record Found");
                return(0);
            }
            else
            {
                return(foundName.CustomerId);
            }
        }
Пример #10
0
        public void GetOrdersByCustomerDB(int customerID)
        {
            string connectionString = SecretConfiguration.ConnectionString;

            DbContextOptions <TopTenMoviesContext> options = new DbContextOptionsBuilder <TopTenMoviesContext>()
                                                             .UseSqlServer(connectionString)
                                                             .Options;

            using var context  = new TopTenMoviesContext(options);
            using var context2 = new TopTenMoviesContext(options);
            using var context3 = new TopTenMoviesContext(options);

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

                if (order.CustomerId == customerID)
                {
                    Console.WriteLine($"[CustomerId] {order.CustomerId} [Location] {location.City} [Title] {title.Title} " +
                                      $"[Quantity] {order.Quantity}");
                }
            }
        }