Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

            string connString = config.GetConnectionString("DefaultConnection");

            IDbConnection conn = new MySqlConnection(connString);
            var           repo = new DapperDepartmentRepository(conn);

            Console.WriteLine("Write a New Department Name");

            var newDepartmentName = Console.ReadLine();

            repo.InsertDepartment(newDepartmentName);

            var departement = repo.GetAllDepartments();

            foreach (var dept in departement)
            {
                Console.WriteLine(dept.Name);
            }

            var productRepo = new DapperProductRepository(conn);

            var products = productRepo.GetAllProducts();

            foreach (var product in products)
            {
                Console.WriteLine(product.Name);
            }

            Console.WriteLine("Let's Make a new product!");
            Console.WriteLine("What's your product's name?");
            string newProduct = Console.ReadLine();

            Console.WriteLine("What's the products category?");
            int newCategoryID = int.Parse(Console.ReadLine());

            Console.WriteLine("And how much is it? ");

            double newPrice = double.Parse(Console.ReadLine());

            productRepo.CreateProduct(newProduct, newPrice, newCategoryID);

            Console.WriteLine("Let's update a price!");

            Console.WriteLine("What is the product id that needs to be updated?");

            int productToBeUpdated = int.Parse(Console.ReadLine());

            Console.WriteLine("What's the new name of this product?");

            string productNameToBeUpdated = Console.ReadLine();

            Console.WriteLine("And What is the new price?");

            double updatedPriceProd = double.Parse(Console.ReadLine());
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            #region Configuration
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

            string connString = config.GetConnectionString("DefaultConnection");
            //Console.WriteLine(connString);
            #endregion

            IDbConnection conn = new MySqlConnection(connString);
            var           repo = new DapperDepartmentRepository(conn);
            //exercise 2 portion:
            var repo2 = new DapperProductRepository(conn);
            //bonus 1 update product
            var repo3 = new DapperProductRepository(conn);
            //bonus 2 extra delete products
            var repo4 = new DapperProductRepository(conn);


            Console.WriteLine("Type a new Department name");
            var newDepartment = Console.ReadLine();
            repo.InsertDepartment(newDepartment);

            Console.WriteLine("Type a new Product name");
            var newProduct = Console.ReadLine();
            Console.WriteLine("What is the price?");
            var newPrice = Console.ReadLine();
            Console.WriteLine("Give it a category ID");
            var newCategoryID = Console.ReadLine();
            repo2.CreateProduct(newProduct, double.Parse(newPrice), int.Parse(newCategoryID));


            Console.WriteLine("What is the product ID of the item you want to change the name of?");
            var productID = Console.ReadLine();
            Console.WriteLine("What do you want to change the product name to?");
            var updateName = Console.ReadLine();
            repo3.UpdateProduct(int.Parse(productID), updateName);


            Console.WriteLine("What is the product ID you would like to delete?");
            var deleteProduct = Console.ReadLine();
            repo4.DeleteProduct(int.Parse(deleteProduct));


            var departments = repo.GetAllDepartments();

            foreach (var dept in departments)
            {
                Console.WriteLine(dept.Name);
            }


            var products = repo2.GetAllProducts();

            foreach (var product in products)
            {
                Console.WriteLine(product.Name);
                Console.WriteLine(product.Price);
                Console.WriteLine(product.CategoryID);
            }


            var products2 = repo3.GetAllProducts();

            foreach (var product in products2)
            {
                Console.WriteLine(product.Name);
            }


            var products3 = repo4.GetAllProducts();

            foreach (var product in products3)
            {
                Console.WriteLine(product.Name);
            }
        }