Ejemplo n.º 1
0
 public void TestNumberProducts()
 {
     using (var dbContext = new storeApplicationContext())
     {
         int numOfProducts = dbContext.Product.Count();
         Assert.Equal(expected: 8, actual: numOfProducts);
     }
 }
Ejemplo n.º 2
0
 public void TestNumberOfStores()
 {
     using (var dbContext = new storeApplicationContext())
     {
         int numOfStores = dbContext.Store.Count();
         Assert.Equal(expected: 7, actual: numOfStores);
     }
 }
Ejemplo n.º 3
0
        public void TestNumberOfCustomers()
        {
            using (var dbContext = new storeApplicationContext())

            {
                int numOfCustomer = dbContext.Customer.Count();
                Assert.Equal(expected: 13, actual: numOfCustomer);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// A void method that dissplays the stores to the console.
 /// </summary>
 public static void display()
 {
     using (var dbContext = new storeApplicationContext())
     {
         Console.WriteLine("These are stores in the system:");
         Console.WriteLine("----------------------------------");
         foreach (var store in dbContext.Store)
         {
             Console.WriteLine(store.Location);
         }
     }
 }
Ejemplo n.º 5
0
 public void searchCustomer(string firstName, string lastName)
 {
     using (var dbContext = new storeApplicationContext())
     {
         foreach (var customer in dbContext.Customer)
         {
             if (customer.FirstName.Equals(firstName) && customer.LastName.Equals(lastName))
             {
                 Assert.Equal($"{firstName} {lastName}", $"{customer.FirstName} {customer.LastName}");
             }
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// adds a customer to the system.
        /// </summary>
        public static void Add()
        {
            using (var dbContext = new storeApplicationContext())
            {
                var customer = new Customer();
                Console.WriteLine("Enter a customer's first name");
                string firstName = Console.ReadLine();
                Console.WriteLine("Enter a customer's last name");
                string lastName = Console.ReadLine();
                Console.WriteLine("Enter a customer's gender");
                string sex = Console.ReadLine();
                customer.FirstName = firstName;
                customer.LastName  = lastName;
                customer.Sex       = sex;


                dbContext.Add(customer);
                dbContext.SaveChanges();
            } Console.WriteLine("Successfully entered the customer in the system");
        }
Ejemplo n.º 7
0
        /// <summary>
        /// A void method that searches a customer in the system
        /// </summary>
        /// <returns></returns>
        public static bool searchCustomer()
        {
            using (var dbContext = new storeApplicationContext())
            {
                Console.WriteLine("Enter customer's first name");
                string inputfirstName = Console.ReadLine();  // first name
                Console.WriteLine("Enter customer's last name");
                string inputLastName = Console.ReadLine();   // last name

                var customer = new Customer();
                customer.FirstName = inputfirstName;
                customer.LastName  = inputLastName;
                foreach (var cust in dbContext.Customer)
                {
                    if (customer.FirstName.Equals(cust.FirstName) && customer.LastName.Equals(cust.LastName))
                    {
                        Console.WriteLine($"{customer.FirstName} {customer.LastName} is in the system");
                        return(true);
                    }
                }
            } Console.WriteLine("The customer is not in the system");
            return(false);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// places an order for the customer.
        /// </summary>
        public static void addOrder()
        {
            using (var dbContext = new storeApplicationContext())
            {
                StoreRep.display();
                Console.WriteLine("------------------------------------");
                Console.WriteLine("Select a store");
                Console.WriteLine("------------------------------------------");
                string selectedStore = Console.ReadLine();
                Console.WriteLine("---------------------------------------------");
                int storeID   = 0; //storing this for later use
                int proID     = 0; //storing the ID for later use
                int inventory = 0; //storing the stock for later use
                foreach (var store in dbContext.Store)
                {
                    if (store.Location.Equals(selectedStore))
                    {
                        storeID = +store.StoreId;
                    }
                }
                foreach (var inventory_stock in dbContext.InventoryStocked)
                {
                    if (inventory_stock.StoreId == storeID)
                    {
                        proID     += inventory_stock.ProdId;
                        inventory += (int)inventory_stock.Stock; //casting to int
                    }
                }

                foreach (var product in dbContext.Product)
                {
                    if (product.ProdId == proID)
                    {
                        Console.WriteLine($"{selectedStore} has the following product and its quantity/stock");
                        Console.WriteLine($"Product name: {product.Name}");
                        Console.WriteLine($"Stock: {inventory}");
                        Console.WriteLine("--------------------------------------------");
                    }
                }

                Console.WriteLine("Enter your first and last name to continue with order");
                string FName = Console.ReadLine();
                string LName = Console.ReadLine();
                int    id    = 0; //store the id of a selected customer.
                foreach (var customer in dbContext.Customer)
                {
                    if (customer.FirstName.Equals(FName) && customer.LastName.Equals(LName))
                    {
                        id += customer.CustId;
                    }
                }
                var order = new Orders(); // instantiate a new order
                order.CustId = id;        //Assigning the foreign key CustId in the order to the id of the selected customer.
                dbContext.Add(order);     // adding the new order in the system
                dbContext.SaveChanges();
                Console.WriteLine("Enter the number of products to put in your cart:");
                int num = int.Parse(Console.ReadLine());
                Console.WriteLine("-----------------------------------------");
                var order_details = new OrderDetails();
                order_details.OrderId = order.OrderId;
                order_details.ProdId  = proID;
                order_details.Qty     = num;
                dbContext.AddAsync(order_details);

                Console.WriteLine("Order has been successfully placed");
                Console.WriteLine("--------------------------------------------------");
            }
        }