Esempio n. 1
0
        public static void SeedProduct(IApplicationBuilder app)
        {
            using var serviceScope = app.ApplicationServices.CreateScope();
            var settings = serviceScope.ServiceProvider.GetService <IOptions <MongoDbSettings> >().Value;
            var context  = new ReadingIsGoodContext(settings);

            var count = context.MongoClient.GetDatabase("ReadingIsGoodDb").GetCollection <Product>("Products").CountDocuments(new BsonDocument());

            if (count > 0)
            {
                return;
            }

            var products = new List <Product>
            {
                new Product {
                    Name = "Modern System Analysis and Design", Price = 40, Quantity = 100
                },
                new Product {
                    Name = "Computer Science", Price = 10, Quantity = 70
                },
                new Product {
                    Name = "Operating System Concepts", Price = 50, Quantity = 20
                },
                new Product {
                    Name = "Software Engineering", Price = 45, Quantity = 90
                },
                new Product {
                    Name = "Data Structures and Algorithms in C++", Price = 60, Quantity = 120
                },
                new Product {
                    Name = "Computer Networks", Price = 35, Quantity = 150
                },
                new Product {
                    Name = "Software Project Management", Price = 15, Quantity = 70
                },
                new Product {
                    Name = "Contemporary Society", Price = 10, Quantity = 60
                },
                new Product {
                    Name = "Discrete Mathematics for Computer Scientists", Price = 50, Quantity = 130
                },
                new Product {
                    Name = "Physics for Scientists and Engineers", Price = 15, Quantity = 40
                },
                new Product {
                    Name = "Probability and Stochastic Processes", Price = 80, Quantity = 20
                },
                new Product {
                    Name = "Calculus", Price = 40, Quantity = 80
                },
                new Product {
                    Name = "A Book on C", Price = 25, Quantity = 90
                },
                new Product {
                    Name = "Clean Code: A Handbook of Agile Software Craftsmanship", Price = 100, Quantity = 50
                },
                new Product {
                    Name = "Design Patterns: Elements of Reusable Object-Oriented Software", Price = 105, Quantity = 50
                },
            };

            context.Products.InsertMany(products);
        }
Esempio n. 2
0
        public static void SeedProduct(IApplicationBuilder app)
        {
            using var serviceScope = app.ApplicationServices.CreateScope();
            var settings = serviceScope.ServiceProvider.GetService <IOptions <MongoDbSettings> >().Value;
            var context  = new ReadingIsGoodContext(settings);

            var count = context.MongoClient.GetDatabase("ReadingIsGoodDb").GetCollection <Product>("Products").CountDocuments(new BsonDocument());

            if (count > 0)
            {
                return;
            }

            var products = new List <Product>
            {
                new Product {
                    Name = "Product One", Price = 15, Quantity = 3
                },
                new Product {
                    Name = "Product Two", Price = 10, Quantity = 4
                },
                new Product {
                    Name = "Product Three", Price = 25, Quantity = 5
                },
                new Product {
                    Name = "Product Four", Price = 18, Quantity = 3
                },
                new Product {
                    Name = "Product Five", Price = 45, Quantity = 2
                },
                new Product {
                    Name = "Product Six", Price = 32, Quantity = 5
                },
                new Product {
                    Name = "Product Seven", Price = 12, Quantity = 7
                },
                new Product {
                    Name = "Product Eight", Price = 100, Quantity = 4
                },
                new Product {
                    Name = "Product Nine", Price = 50, Quantity = 3
                },
                new Product {
                    Name = "Product Ten", Price = 15, Quantity = 2
                },
                new Product {
                    Name = "Product Eleven", Price = 12, Quantity = 2
                },
                new Product {
                    Name = "Product Twelve", Price = 45, Quantity = 6
                },
                new Product {
                    Name = "Product Thirteen", Price = 35, Quantity = 1
                },
                new Product {
                    Name = "Product Fourteen", Price = 20, Quantity = 3
                },
                new Product {
                    Name = "Product Fifteen", Price = 53, Quantity = 2
                },
            };

            context.Products.InsertMany(products);
        }