public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (dbContext == null)
            {
                throw new ArgumentNullException(nameof(dbContext));
            }

            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            var logger = serviceProvider.GetService <ILoggerFactory>()
                         .CreateLogger(typeof(VinylExchangeDbContextSeeder));

            var seeders = new List <ISeeder>
            {
                new RolesSeeder(),
                new UsersSeeder(),
                new GenresSeeder(),
                new StylesSeeder(),
                new ReleasesSeeder(),
                new ReleaseFilesSeeder(),
                new StyleReleasesSeeder()
            };

            foreach (var seeder in seeders)
            {
                await seeder.SeedAsync(dbContext, serviceProvider);

                await dbContext.SaveChangesAsync();

                logger.LogInformation($"Seeder {seeder.GetType().Name} done.");
            }
        }
Example #2
0
        private static async Task SeedStyleAsync(VinylExchangeDbContext dbContext, string name, int genreId)
        {
            var style = new Style {
                Name = name, GenreId = genreId
            };

            await dbContext.Styles.AddAsync(style);

            await dbContext.SaveChangesAsync();
        }
Example #3
0
        public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (!dbContext.Genres.Any())
            {
                await SeedGenreAsync(dbContext, "Electronic");

                await SeedGenreAsync(dbContext, "Rock");

                await SeedGenreAsync(dbContext, "Hip Hop");

                await SeedGenreAsync(dbContext, "Jazz");

                await dbContext.SaveChangesAsync();
            }
        }
        private static async Task SeedReleaseFileAsync(
            VinylExchangeDbContext dbContext,
            Guid releaseId,
            FileType fileType,
            string fileName,
            bool isPrewiew)
        {
            var releaseFile = new ReleaseFile
            {
                ReleaseId = releaseId,
                Path      = @"\Releases\" + fileType + "\\",
                FileName  = fileName,
                IsPreview = isPrewiew,
                FileType  = fileType
            };

            await dbContext.ReleaseFiles.AddAsync(releaseFile);

            await dbContext.SaveChangesAsync();
        }
Example #5
0
        private static async Task SeedReleaseAsync(
            VinylExchangeDbContext dbContext,
            Guid id,
            string artist,
            string title,
            string format,
            int year,
            string label)
        {
            var release = new Release
            {
                Id     = id,
                Artist = artist,
                Title  = title,
                Format = format,
                Year   = year,
                Label  = label
            };

            await dbContext.Releases.AddAsync(release);

            await dbContext.SaveChangesAsync();
        }