Beispiel #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 DapperDepartamentRepository(conn);

            var departaments = repo.GetAllDepartaments();

            Console.WriteLine("DepartamentID, Name");

            foreach (var item in departaments)
            {
                Console.WriteLine($"{ item.DepartmentID} { item.Name}");
            }

            //Console.WriteLine("Type the new Department");

            //string userInput = Console.ReadLine();

            //repo.InsertDepartment(userInput);



            var repoProducts = new DapperProductRepository(conn);

            repoProducts.CreateProduct();

            var products = repoProducts.GetAllProducts();

            Console.WriteLine("_______________________________");

            Console.WriteLine("CategoryId, Name, OnSale, Price, ProductID, StockLevel");

            foreach (var product in products)
            {
                Console.WriteLine($"{product.CategoryId} , {product.Name}, {product.OnSale}, {product.Price}, {product.ProductID}, {product.StockLevel}");
            }
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

            // Creating connection string using info from appsettings.json file
            string connString = config.GetConnectionString("DefaultConnection");

            // Using that string to make connection to database
            IDbConnection conn = new MySqlConnection(connString);

            var deptRepo = new DapperDepartmentRepository(conn);

            //Console.WriteLine("Type a new Department name");

            //var newDepartment = Console.ReadLine();

            //deptRepo.InsertDepartment(newDepartment);

            var departments = deptRepo.GetAllDepartments();

            foreach (var dept in departments)
            {
                Console.WriteLine($"{dept.DepartmentID} : {dept.Name}");
            }
            Console.WriteLine();

            // Creating new Product Repository
            var prodRepo = new DapperProductRepository(conn);

            // Bringing in all Products from database
            var allProducts = prodRepo.GetAllProducts();

            // take a look
            //foreach (var prod in allProducts)
            //{
            //    Console.WriteLine($"{prod.ProductID} : {prod.Name} : {prod.Price} : {prod.CategoryID} : {prod.OnSale} : {prod.StockLevel}");
            //}

            // Adding a new item in the Products table
            //prodRepo.CreateProduct("MacBook Air", 1000.00, 1);

            //foreach (var prod in allProducts)
            //{
            //    Console.WriteLine($"{prod.ProductID} : {prod.Name} : {prod.Price} : {prod.CategoryID} : {prod.OnSale} : {prod.StockLevel}");
            //}

            //prodRepo.UpdateStockLevel(940, "100");

            // prodRepo.DeleteProduct(941);

            var allComputers  = prodRepo.GetComputers();
            var catOfProducts = prodRepo.GetCategoryProducts(2);

            //foreach (var comp in catOfProducts)
            //{
            //    Console.WriteLine($"{comp.ProductID} : {comp.Name} : {comp.Price}");
            //}

            var empRepo      = new DapperEmployeeRepository(conn);
            var allEmployees = empRepo.GetAllEmployees();

            //Console.WriteLine("What is the new employee's First Name?");
            //var FirstName = Console.ReadLine();
            //Console.WriteLine("What is the new employee's Middle Initial?");
            //var MiddleInitial = Console.ReadLine();
            //Console.WriteLine("What is the new employee's Last Name?");
            //var LastName = Console.ReadLine();
            //Console.WriteLine("What is the new employee's Job Title?");
            //var Title = Console.ReadLine();

            // empRepo.AddEmployee(FirstName, MiddleInitial, LastName, Title);

            foreach (var emp in allEmployees)
            {
                Console.WriteLine($"{emp.EmployeeID} : {emp.LastName} : {emp.Title}");
            }

            // Updating EmailAddress in database with method
            var emailAddress = "*****@*****.**";

            empRepo.UpdateEmail(34618, emailAddress);
        }