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();
        }
Exemple #2
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();
        }
Exemple #3
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();
        }