public static void Initialize(MarketPlaceContext context)
        {
            //using Microsoft.EntityFrameworkCore;
            context.Database.Migrate();

            // Look for any products.
            if (context.Products.Any())
            {
                return;   // DB has been seeded
            }

            //using MarketPlaceService.Models;
            var products = new Product[] {
                new Product {
                    Name = "Product 1", Description = "First Sample Product", Price = 1234, UserName = "******"
                },
                new Product {
                    Name = "Product 2", Description = "Lorem Ipsum", Price = 555, UserName = "******"
                },
                new Product {
                    Name = "Product 3", Description = "Third Sample Product", Price = 333, UserName = "******"
                },
                new Product {
                    Name = "Product 4", Description = "Fourth Sample Product", Price = 44, UserName = "******"
                }
            };

            foreach (var product in products)
            {
                context.Products.Add(product);
            }

            context.SaveChanges();
        }
        public static void Initialize(MarketPlaceContext context, string path)
        {
            //using Microsoft.EntityFrameworkCore;
            context.Database.Migrate();

            // Look for any products.
            if (context.Products.Any())
            {
                return;   // DB has been seeded
            }

            //using MarketPlaceService.Models;
            var products = new Product[] {
                new Product {
                    Name      = "Product 1", Description = "First Sample Product", Price = 1234, UserName = "******",
                    ImageFile = File.ReadAllBytes($@"{path}\Images\flower.jpg"), ImageMimeType = "image/jpeg"
                },
                new Product {
                    Name      = "Product 2", Description = "Lorem Ipsum", Price = 555, UserName = "******",
                    ImageFile = File.ReadAllBytes($@"{path}\Images\orchard.jpg"), ImageMimeType = "image/jpeg"
                },
                new Product {
                    Name      = "Product 3", Description = "Third Sample Product", Price = 333, UserName = "******",
                    ImageFile = File.ReadAllBytes($@"{path}\Images\path.jpg"), ImageMimeType = "image/jpeg"
                },
                new Product {
                    Name      = "Product 4", Description = "Fourth Sample Product", Price = 44, UserName = "******",
                    ImageFile = File.ReadAllBytes($@"{path}\Images\blackberries.jpg"), ImageMimeType = "image/jpeg"
                }
            };

            foreach (var product in products)
            {
                context.Products.Add(product);
            }

            context.SaveChanges();
        }
        public ProductsRepository(MarketPlaceContext context)
        {
            _context = context;

            //init our db with some products if empty
            if (_context.Products.Count() == 0)
            {
                _context.Products.AddRange(
                    new Product {
                    Name = "Product 1", Description = "First Sample Product", Price = 1234
                },
                    new Product {
                    Name = "Product 2", Description = "Second Sample Product", Price = 2345
                },
                    new Product {
                    Name = "Product 3", Description = "Third Sample Product", Price = 3456
                },
                    new Product {
                    Name = "Product 4", Description = "Fourth Sample Product", Price = 4567
                });
                _context.SaveChanges();
            }
        }
Exemple #4
0
 public ProductsRepository(MarketPlaceContext context)
 {
     _context = context;
 }