Пример #1
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);
            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
        }
Пример #3
0
        public ActionResult Post([FromBody] DtoProductListing obj)
        {
            var repo      = new DapperProductRepository();
            var adminRepo = new DapperAdminRepository();

            var srv = new SrvProductListingV1(repo, adminRepo, cache);
            var ret = new DtoProductListingResult();

            if (!srv.Exec(network, obj, ref ret))
            {
                return(BadRequest(srv.Error));
            }

            return(Ok(ret));
        }