Exemple #1
0
        public static void DepartmentUpdate()
        {
            var repo = new DapperDepartmentRepository(conn);

            Console.WriteLine($"Would you like to update a department? yes or no");

            if (Console.ReadLine().ToUpper() == "YES")
            {
                Console.WriteLine($"What is the ID of the Department you would like to update?");

                var id = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine($"What would you like to change the name of the department to?");

                var newName = Console.ReadLine();

                repo.UpdateDepartment(id, newName);

                var depts = repo.GetDepartments();

                foreach (var item in depts)
                {
                    Console.WriteLine($"{item.DepartmentID} {item.Name}");
                }
            }
        }
Exemple #2
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);

            var departments = repo.GetAllDepartments();

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

            var prod     = new DapperProductRepository(conn);
            var products = prod.GetAllProducts();

            foreach (var product in products)
            {
                Console.WriteLine($"Product: {product.Name}\nPrice: {product.Price}\nCategory ID: {product.CategoryID}\n--------------------");
            }
        }
Exemple #3
0
        public static void ListDepartments()
        {
            var repo = new DapperDepartmentRepository(conn);

            var departments = repo.GetDepartments();

            foreach (var item in departments)
            {
                Console.WriteLine($"{item.DepartmentID} {item.Name}");
            }
        }
Exemple #4
0
        static void Main(string[] args)
        {
            #region Configuration
            var config = new ConfigurationBuilder()
                         .SetBasePath(Directory.GetCurrentDirectory())
                         .AddJsonFile("appsettings.json")
                         .Build();

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

            IDbConnection conn = new MySqlConnection(connString);
            DapperDepartmentRepository repo = new DapperDepartmentRepository(conn);
            //Exercise 2 portion:
            DapperProductRepository repo2 = new DapperProductRepository(conn);

            Console.WriteLine("Hello user, here are the current departments:");
            var depos = repo.GetAllDepartments();
            {
                foreach (var depo in depos)
                {
                    Console.WriteLine($"Id: {depo.DepartmentID} Name: {depo.Name}");
                }
            }
            Console.WriteLine("Please press enter . . .");
            Console.ReadLine();


            Console.WriteLine("Do you want to add a department???");
            string userResponse = Console.ReadLine();

            if (userResponse.ToLower() == "yes")
            {
                Console.WriteLine("What is the name of your new Department??");
                userResponse = Console.ReadLine();

                repo.InsertDepartment(userResponse);
                Print(repo.GetAllDepartments());
            }


            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("Have a great day.");
        }
Exemple #5
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 repoDepart = new DapperDepartmentRepository(conn);

            var departments = repoDepart.GetAllDepartments();

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

            var repoProd = new DapperProductsRepository(conn);
            var products = repoProd.GetAllProducts();

            foreach (var prod in products)
            {
                Console.WriteLine($"{prod.ProductID} {prod.Name} {prod.Price}");
            }

            var repoEmplo = new DapperEmployeesRepository(conn);
            var employees = repoEmplo.GetAllEmployee();

            foreach (var empl in employees)
            {
                Console.WriteLine($"{empl.EmployeeId} {empl.FirstName} {empl.LastName} {empl.Title}");
            }
        }