예제 #1
0
        static void Main(string[] args)
        {
            var     connectionString = ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
            Product prod2            = null;
            var     repo             = new DapperProductRepository(connectionString);



            prod2 = new Product
            {
                Id   = 1000,
                Name = ""
            };
            if (prod2 != null)
            {
                prod2.Name = "update was successful";
                prod2.Id   = 1028;
                repo.UpdateProduct(prod2);
            }
            prod2.Name = "Here is a new product!";
            prod2.Id   = 1005;
            repo.InsertProduct(prod2);
            repo.DeleteProduct(1028);
            foreach (var prod in repo.GetProducts())
            {
                Console.WriteLine("Product Name: " + prod.Name);
            }
            foreach (var prod in repo.GetProductsAndReview())
            {
                if (prod2 == null)
                {
                    prod2 = prod;
                }
                ;

                Console.WriteLine(prod.Name);
            }
            repo.GetProductsWithReview();
            repo.GetProductsAndReview();
            Console.WriteLine("\nThe Program has ended, press any key to exit...");
            Console.ReadLine();
        }
예제 #2
0
        static void Main(string[] args)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

            using (var conn = new MySqlConnection(connectionString))
            {
                conn.Open();

                var repo = new DapperProductRepository(conn);
                foreach (var prod in repo.GetProducts())
                {
                    Console.WriteLine(prod.ProductId + " " + prod.Name + " " + prod.Color);
                }

                var product = new Product
                {
                    ProductId        = 5,
                    Name             = "Bike Rack",
                    ProductNumber    = "BR-1004",
                    Color            = "Blue",
                    SafetyStockLevel = 1000,
                    ReorderPoint     = 500,
                    StandardCost     = 500.75,
                    ListPrice        = 1025.36,
                    ModifiedDate     = DateTime.Now
                };

                repo.InsertProduct(product);

                var oProduct = new Product()
                {
                    ProductId = 1,
                    Name      = "Road Black, 52"
                };

                repo.UpdateProduct(oProduct);

                repo.DeleteProduct(998);

                Console.ReadLine();
            }
        }
예제 #3
0
        static void Main(string[] args)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["AdventureWorks"].ConnectionString;
            var connection       = new MySqlConnection(connectionString);

            var repo = new DapperProductRepository(connection);

            Product product = null;

            var quit = false;

            while (!quit)
            {
                Console.WriteLine("ShowAll, Delete, Update, Insert, LeftJoin, InnerJoin, Quit");
                var userInput = Console.ReadLine().ToLower();

                if (userInput == "quit")
                {
                    quit = true;
                }

                if (userInput == "leftjoin")
                {
                    foreach (var prod in repo.GetProductsAndReviews())
                    {
                        Console.WriteLine("Product Name:" + prod.Name + " Product ID: " + prod.ProductId + "Rating: " + prod.Rating);
                    }
                    Console.WriteLine();
                }

                if (userInput == "innerjoin")
                {
                    foreach (var prod in repo.GetProductsWithReviews())
                    {
                        Console.WriteLine("Product Name:" + prod.Name + " Product ID: " + prod.ProductId + "Rating: " + prod.Rating);
                    }
                    Console.WriteLine();
                }

                if (userInput == "showall")
                {
                    foreach (var prod in repo.GetProducts())
                    {
                        Console.WriteLine("Product Name:" + prod.Name + " Product ID: " + prod.ProductId);
                    }
                    Console.WriteLine();
                }

                if (userInput == "delete")
                {
                    Console.WriteLine("Enter Product ID to DELETE.");
                    var id = Convert.ToInt32(Console.ReadLine());
                    repo.DeleteProduct(id);

                    Console.WriteLine($"Deleted Product with ID {id}");
                }

                if (userInput == "insert")
                {
                    Console.WriteLine("Enter Product Name to insert.");
                    string prodNewName = Console.ReadLine();

                    product = new Product
                    {
                        Name = prodNewName
                    };
                    repo.InsertProduct(product);
                }
                if (userInput == "update")
                {
                    Console.WriteLine("Enter the Product ID for the name you would like to change");
                    var id = Convert.ToInt32(Console.ReadLine());

                    product = new Product {
                        ProductId = id
                    };

                    Console.WriteLine($"Change name to what?");

                    product.Name = Console.ReadLine();

                    repo.UpdateProduct(product);
                }
            }
        }
예제 #4
0
        static void Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                                .SetBasePath(Directory.GetCurrentDirectory())
                                .AddJsonFile("appsettings.json")
            #if DEBUG
                                .AddJsonFile("appsettings.Debug.json")
            #else
                                .AddJsonFile("appsettings.Release.json")
            #endif
                                .Build();

            var connectionString = configuration.GetConnectionString("DefaultConnection");

            var dapperRepo = new DapperProductRepository(connectionString);
            var repo       = new ProductRepository(connectionString);

            var newItem = new Product()
            {
                Name = "testProduct"
            };
            var updateItem = new Product()
            {
                Name = "updatedTestProduct"
            };

            //GetProducts
            foreach (var prod in repo.GetProducts())
            {
                Console.WriteLine("Product Name: " + prod.Name);
            }
            WaitForEnterKey();

            //GetProducts with Dapper
            foreach (var prod in dapperRepo.GetProducts())
            {
                Console.WriteLine("Product Name: " + prod.Name);
            }
            WaitForEnterKey();

            //GetProductsWithReview
            foreach (var prod in repo.GetProductsWithReview())
            {
                Console.WriteLine("Product Name: " + prod.Name + "\n\nReview: " + prod.Review + "\n\n");
            }
            WaitForEnterKey();

            //GetProductsWithReview with Dapper
            foreach (var prod in dapperRepo.GetProductsWithReview())
            {
                Console.WriteLine("Product Name: " + prod.Name + "\n\nReview: " + prod.Review + "\n\n");
            }
            WaitForEnterKey();

            //GetProductsAndReview
            foreach (var prod in repo.GetProductsAndReview())
            {
                Console.WriteLine("Product Name: " + prod.Name + "\n\nReview: " + prod.Review + "\n\n");
            }
            WaitForEnterKey();

            //GetProductsAndReview with Dapper
            foreach (var prod in dapperRepo.GetProductsAndReview())
            {
                Console.WriteLine("Product Name: " + prod.Name + "\n\nReview: " + prod.Review + "\n\n");
            }
            WaitForEnterKey();


            //InsertProduct
            Console.WriteLine("Press Enter to Add a new Product");
            Console.ReadKey();
            repo.InsertProduct(newItem);
            var newestId = repo.GetNewestId().Last().Id;

            Console.WriteLine($"\nNew Item Added\nID: {newestId}\nName: {newItem.Name}");
            WaitForEnterKey();

            //UpdateProduct
            updateItem.Id = newestId;
            Console.WriteLine("Press Enter to Update the new Product");
            Console.ReadKey();
            repo.UpdateProduct(updateItem);
            Console.WriteLine($"\nItem Updated\nID: {newestId}\nName: {updateItem.Name}");
            WaitForEnterKey();

            //DeleteProduct
            Console.WriteLine("Press Enter to Delete the new Product");
            Console.ReadKey();
            repo.DeleteProduct(updateItem.Id);
            Console.WriteLine($"\nItem with ID: {newestId} Deleted");
            WaitForEnterKey();



            //InsertProduct with Dapper
            Console.WriteLine("Press Enter to Add a new Product with Dapper");
            Console.ReadKey();
            dapperRepo.InsertProduct(newItem);
            newestId = dapperRepo.GetNewestId().Last().Id;
            Console.WriteLine($"\nNew Item Added\nID: {newestId}\nName: {newItem.Name}");
            WaitForEnterKey();

            //UpdateProduct with Dapper
            updateItem.Id = dapperRepo.GetNewestId().Last().Id;
            Console.WriteLine("Press Enter to Update the new Product with Dapper");
            Console.ReadKey();
            dapperRepo.UpdateProduct(updateItem);
            Console.WriteLine($"\nItem Updated\nID: {newestId}\nName: {updateItem.Name}");
            WaitForEnterKey();

            //DeleteProduct with Dapper
            Console.WriteLine("Press Enter to Delete the new Product with Dapper");
            Console.ReadKey();
            dapperRepo.DeleteProduct(updateItem.Id);
            Console.WriteLine($"\nItem with ID: {newestId} Deleted");
            WaitForEnterKey();
        }