コード例 #1
0
ファイル: Program.cs プロジェクト: ADariusC03/BestBuyPractice
        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);
            DapperProductRepository repos = new DapperProductRepository(conn);

            Console.WriteLine("Howdy Partner, here are the current products: ");
            Console.WriteLine("Press enter......");
            Console.ReadLine();

            var pro = repos.GetAllProducts();
            Print(pro);


            Console.WriteLine("Do you wish to add another product to table?");
            string userInput = Console.ReadLine();
            if (userInput.ToLower() == "yes")
            {
                Console.WriteLine("What is the name of your new products?");
                userInput = Console.ReadLine();

                repos.InsertProduct(userInput);
                Print(repos.GetAllProducts());
            }
            Console.WriteLine("Thanks. See you later!");
        }
コード例 #2
0
        CtrlProductListing Setup()
        {
            #region - code -

            var tst = new CtrlProductListing(null, null)
            {
                network = new Master.LocalNetwork {
                    sqlServer = connStr
                }
            };

            SetupDatabase();

            using (var db = new NpgsqlConnection(connStr))
            {
                db.Open();

                var repo = new DapperProductRepository();

                var repoAdmin = new DapperAdminRepository();

                repoAdmin.InsertBrand(db, new Brand {
                    stName = "Samsung"
                });
                repoAdmin.InsertBrand(db, new Brand {
                    stName = "Toshiba"
                });

                repoAdmin.InsertCategory(db, new Category {
                    stName = "TVs", fkMainCategory = 0, fkCountry = 1
                });

                repo.InsertProduct(db, new Product {
                    stName = "Livro", nuPrice = 12345, stDesc = "Livro desc", fkBrand = 1, fkCategory = 1, fkCountry = 1
                });
                repo.InsertProductCatalog(db, new ProductCatalog {
                    stTag = "Livro"
                });
                repo.InsertProductCatalogLink(db, new ProductCatalogLink {
                    fkProduct = 1, fkProductCatalog = 1
                });

                db.Close();
            }

            return(tst);

            #endregion
        }