Exemple #1
0
        public static void Seed(IServiceProvider serviceProvider)
        {
            using var context = new PlaceDbContext(serviceProvider.GetRequiredService <DbContextOptions <PlaceDbContext> >());

            if (context.Places.Any())
            {
                return;
            }

            context.Places.AddRange(
                new Place
            {
                Id           = 1,
                Name         = "Coron Island",
                Location     = "Palawan, Philippines",
                About        = "Coron is one of the top destinations for tourists to add to their wish list.",
                Reviews      = 10,
                ImageDataUrl = GetImage("coron_island.jpg", "image/jpeg"),
                LastUpdated  = DateTime.Now
            },
                new Place
            {
                Id           = 2,
                Name         = "Olsob Cebu",
                Location     = "Cebu, Philippines",
                About        = "Whale shark watching is the most popular tourist attraction in Cebu.",
                Reviews      = 3,
                ImageDataUrl = GetImage("oslob_whalesharks.png", "image/png"),
                LastUpdated  = DateTime.Now
            }
                );

            context.SaveChanges();
        }
        public static void Seed(IServiceProvider serviceProvider)
        {
            using (var context = new PlaceDbContext(serviceProvider.GetRequiredService <DbContextOptions <PlaceDbContext> >()))
            {
                if (context.Places.Any())
                {
                    return;
                }

                context.Places.AddRange(
                    new Place
                {
                    Id          = 1,
                    Name        = "Central Rattanathibeth",
                    Location    = "Nonthaburi",
                    About       = "One of best department in thailand",
                    Reviews     = 10,
                    ImageData   = GetImage("central.jpg", "image/jpeg"),
                    LastUpdated = DateTime.Now
                },
                    new Place
                {
                    Id          = 2,
                    Name        = "TheMall Ngamwongwan",
                    Location    = "Nonthaburi",
                    About       = "One of best department in thailand",
                    Reviews     = 10,
                    ImageData   = GetImage("themall.png", "image/png"),
                    LastUpdated = DateTime.Now
                },
                    new Place
                {
                    Id          = 3,
                    Name        = "Home Pro",
                    Location    = "Bkk",
                    About       = "Shopping Mall",
                    Reviews     = 10,
                    ImageData   = GetImage("homepro.jpg", "image/jpg"),
                    LastUpdated = DateTime.Now
                }
                    );

                context.SaveChanges();
            }
        }