示例#1
0
        public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
        {
            var roleManager = serviceProvider.GetRequiredService <RoleManager <VinylExchangeRole> >();

            await SeedRoleAsync(roleManager, Roles.Admin);
            await SeedRoleAsync(roleManager, Roles.User);
        }
        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.");
            }
        }
示例#3
0
        public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (!dbContext.Styles.Any())
            {
                await SeedStyleAsync(dbContext, "IDM", 1);              // 1
                await SeedStyleAsync(dbContext, "Techno", 1);           // 2
                await SeedStyleAsync(dbContext, "House", 1);            // 3
                await SeedStyleAsync(dbContext, "Trance", 1);           // 4
                await SeedStyleAsync(dbContext, "Drum And Bass", 1);    // 5
                await SeedStyleAsync(dbContext, "Hardcore", 1);         // 6
                await SeedStyleAsync(dbContext, "Downtempo", 1);        // 7
                await SeedStyleAsync(dbContext, "Breakbeat", 1);        // 8
                await SeedStyleAsync(dbContext, "Big Beat", 1);         // 9
                await SeedStyleAsync(dbContext, "Ambient", 1);          // 10
                await SeedStyleAsync(dbContext, "Leftfield", 1);        // 11
                await SeedStyleAsync(dbContext, "Abstract", 1);         // 12
                await SeedStyleAsync(dbContext, "Electro", 1);          // 13
                await SeedStyleAsync(dbContext, "Experimental", 1);     // 14

                await SeedStyleAsync(dbContext, "Metal", 2);            // 12
                await SeedStyleAsync(dbContext, "Trash Metal", 2);      // 13
                await SeedStyleAsync(dbContext, "Alternative Rock", 2); // 14

                await SeedStyleAsync(dbContext, "Rap", 3);              // 15

                await SeedStyleAsync(dbContext, "Easy Listening", 4);   // 16
            }
        }
示例#4
0
        private static async Task SeedGenreAsync(VinylExchangeDbContext dbContext, string name)
        {
            var genre = new Genre {
                Name = name
            };

            await dbContext.Genres.AddAsync(genre);
        }
示例#5
0
        private static async Task SeedStyleRelease(VinylExchangeDbContext dbContext, Guid releaseId, int styleId)
        {
            var styleRelease = new StyleRelease {
                ReleaseId = releaseId, StyleId = styleId
            };

            await dbContext.StyleReleases.AddAsync(styleRelease);
        }
 public SaleMessagesService(
     VinylExchangeDbContext dbContext,
     ISalesEntityRetriever salesEntityRetriever,
     IUsersEntityRetriever usersEntityRetriever)
 {
     this.dbContext            = dbContext;
     this.salesEntityRetriever = salesEntityRetriever;
     this.usersEntityRetriever = usersEntityRetriever;
 }
示例#7
0
 public CollectionsService(
     VinylExchangeDbContext dbContext,
     IReleasesEntityRetriever releasesEntityRetriever,
     IUsersEntityRetriever usersEntityRetriever)
 {
     this.dbContext = dbContext;
     this.releasesEntityRetriever = releasesEntityRetriever;
     this.usersEntityRetriever    = usersEntityRetriever;
 }
示例#8
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();
        }
示例#9
0
        public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
        {
            var userManager = serviceProvider.GetRequiredService <UserManager <VinylExchangeUser> >();

            var configuration = serviceProvider.GetRequiredService <IConfiguration>();

            await SeedAdminAsync(dbContext, userManager, configuration["SysAdminUserName"],
                                 configuration["SysAdminPassword"], "*****@*****.**");
            await SeedUserAsync(dbContext, userManager, "testUserOne", "testUserOnePassword", "*****@*****.**");
            await SeedUserAsync(dbContext, userManager, "testUserTwo", "testUserTwoPassword", "*****@*****.**");
        }
示例#10
0
 public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
 {
     if (!dbContext.Releases.Any())
     {
         await SeedReleaseAsync(
             dbContext,
             Guid.Parse("3cc8ee5c-4dc3-4009-b3fc-d768e6a564f8"),
             "Aphex Twin",
             "Selected Ambient Works 85-92",
             "4x Lp",
             1992,
             "Warp");
         await SeedReleaseAsync(
             dbContext,
             Guid.Parse("1cf99ed0-a565-4d2a-928b-99a0fd851d9b"),
             "De Lacy",
             "Hideaway",
             "Vinyl 12'",
             1995,
             "Deconstruction");
         await SeedReleaseAsync(
             dbContext,
             Guid.Parse("22d663f8-6bd6-4f20-9f74-bd82da066e42"),
             "Sasha",
             "Wavy Gravy",
             "Vinyl 12'",
             2002,
             "BMG UK & Ireland Ltd");
         await SeedReleaseAsync(
             dbContext,
             Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"),
             "Aphex Twin",
             "Windolicker",
             "Vinyl 12'",
             1999,
             "Warp");
         await SeedReleaseAsync(
             dbContext,
             Guid.Parse("4b3b4142-3621-4256-a209-4468a6c5ca4c"),
             "Squarepusher",
             "Ultravisitor",
             "2 x Vinyl LP",
             2004,
             "Warp");
         await SeedReleaseAsync(
             dbContext,
             Guid.Parse("6eaabd12-fd4f-4b69-b0bd-f172f9b42085"),
             "Mobb Deep",
             "Shook Ones",
             "Vinyl 12 Promo",
             1994,
             "Loud Records");
     }
 }
示例#11
0
 public SalesService(
     VinylExchangeDbContext dbContext,
     IAddressesEntityRetriever addressesEntityRetriever,
     IUsersEntityRetriever usersEntityRetriever,
     IReleasesEntityRetriever releasesEntityRetriever)
 {
     this.dbContext = dbContext;
     this.addressesEntityRetriever = addressesEntityRetriever;
     this.usersEntityRetriever     = usersEntityRetriever;
     this.releasesEntityRetriever  = releasesEntityRetriever;
 }
示例#12
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();
            }
        }
示例#13
0
        public static VinylExchangeDbContext CreateDbContext()
        {
            var options = new DbContextOptionsBuilder <VinylExchangeDbContext>()
                          .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options;

            var modelBuilder = new ModelBuilder(new ConventionSet());

            var dbContext = new VinylExchangeDbContext(options, null);

            var onModelCreatingMethod = dbContext.GetType().GetMethod(
                "OnModelCreating",
                BindingFlags.Instance | BindingFlags.NonPublic);

            onModelCreatingMethod.Invoke(dbContext, new object[] { modelBuilder });

            return(dbContext);
        }
示例#14
0
        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();
        }
示例#15
0
        private static async Task SeedUserAsync(
            VinylExchangeDbContext dbContext,
            UserManager <VinylExchangeUser> userManager,
            string username,
            string password,
            string email)
        {
            if (!dbContext.Users.Where(u => u.UserName != "sysadmin").Any())
            {
                var user = await CreateUserAsync(userManager, username, password, email);

                var setAdminRoleResult = await userManager.AddToRoleAsync(user, Roles.User);

                if (!setAdminRoleResult.Succeeded)
                {
                    throw new Exception(
                              string.Join(Environment.NewLine, setAdminRoleResult.Errors.Select(e => e.Description)));
                }
            }
        }
示例#16
0
        public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (!dbContext.StyleReleases.Any())
            {
                await SeedStyleRelease(dbContext, Guid.Parse("3cc8ee5c-4dc3-4009-b3fc-d768e6a564f8"), 7);
                await SeedStyleRelease(dbContext, Guid.Parse("3cc8ee5c-4dc3-4009-b3fc-d768e6a564f8"), 10);

                await SeedStyleRelease(dbContext, Guid.Parse("1cf99ed0-a565-4d2a-928b-99a0fd851d9b"), 3);

                await SeedStyleRelease(dbContext, Guid.Parse("22d663f8-6bd6-4f20-9f74-bd82da066e42"), 7);
                await SeedStyleRelease(dbContext, Guid.Parse("22d663f8-6bd6-4f20-9f74-bd82da066e42"), 8);

                await SeedStyleRelease(dbContext, Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"), 12);
                await SeedStyleRelease(dbContext, Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"), 13);
                await SeedStyleRelease(dbContext, Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"), 14);

                await SeedStyleRelease(dbContext, Guid.Parse("4b3b4142-3621-4256-a209-4468a6c5ca4c"), 1);

                await SeedStyleRelease(dbContext, Guid.Parse("6eaabd12-fd4f-4b69-b0bd-f172f9b42085"), 15);
            }
        }
示例#17
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();
        }
 public ReleaseFilesService(VinylExchangeDbContext dbContext, IFileManager fileManager)
 {
     this.dbContext   = dbContext;
     this.fileManager = fileManager;
 }
示例#19
0
 public ReleasesService(VinylExchangeDbContext dbContext, IReleaseFilesService releaseFilesService)
 {
     this.dbContext           = dbContext;
     this.releaseFilesService = releaseFilesService;
 }
示例#20
0
 public AddressesService(VinylExchangeDbContext dbContext)
 {
     this.dbContext = dbContext;
 }
示例#21
0
 public UsersAvatarService(VinylExchangeDbContext dbContext, IUsersEntityRetriever usersEntityRetriever)
 {
     this.dbContext            = dbContext;
     this.usersEntityRetriever = usersEntityRetriever;
 }
示例#22
0
 public StylesService(VinylExchangeDbContext dbContext, IGenresEntityRetriever genresEntityRetriever)
 {
     this.dbContext             = dbContext;
     this.genresEntityRetriever = genresEntityRetriever;
 }
示例#23
0
 public SaleLogsService(VinylExchangeDbContext dbContext, ISalesEntityRetriever salesEntityRetriever)
 {
     this.dbContext            = dbContext;
     this.salesEntityRetriever = salesEntityRetriever;
 }
示例#24
0
        public async Task SeedAsync(VinylExchangeDbContext dbContext, IServiceProvider serviceProvider)
        {
            if (!dbContext.ReleaseFiles.Any())
            {
                // Aphex Twin - Selected Ambient Works 85 - 92
                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("3cc8ee5c-4dc3-4009-b3fc-d768e6a564f8"),
                    FileType.Image,
                    "e10ccdba-7f17-4831-a9e9-335a3f2ec96c@---@ZG93bmxvYWQ=.jpg",
                    true);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("3cc8ee5c-4dc3-4009-b3fc-d768e6a564f8"),
                    FileType.Audio,
                    "0d8f30d3-67a7-48b6-a2ad-f69d0afebed8@---@QXBoZXggVHdpbiAtIEFnZWlzcG9saXM=.mp3",
                    false);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("3cc8ee5c-4dc3-4009-b3fc-d768e6a564f8"),
                    FileType.Audio,
                    "863aad8d-a80a-453d-b9c8-010e4d84c564@---@QXBoZXggVHdpbiAtIFh0YWw=.mp3",
                    false);

                // De Lacy - Hideaway
                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("1cf99ed0-a565-4d2a-928b-99a0fd851d9b"),
                    FileType.Image,
                    "0002affb-a428-4279-bfc0-5202a1558850@---@Ui00MzgwMS0xMjM5MDM4Nzg2LmpwZWc=.jpg",
                    true);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("1cf99ed0-a565-4d2a-928b-99a0fd851d9b"),
                    FileType.Audio,
                    "de61302f-01a7-446f-9d15-651ab4784d82@[email protected]",
                    false);

                //// Sasha - Wavy Gravy

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("22d663f8-6bd6-4f20-9f74-bd82da066e42"),
                    FileType.Image,
                    "210d3e68-f74d-45f1-9488-8890b58503fd@[email protected]",
                    true);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("22d663f8-6bd6-4f20-9f74-bd82da066e42"),
                    FileType.Audio,
                    "129606d8-f943-4fbb-a21b-928af0252490@[email protected]",
                    false);

                //// Aphex Twin - Windowlicker

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"),
                    FileType.Image,
                    "bf741066-f760-4a70-a213-8dcf7683d1d9@---@YTNkYTRiYmIzY2JkMTI0Mjk1NmFlNjAxMTVlMTA1MTA=.jpg",
                    true);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"),
                    FileType.Image,
                    "3853fa95-e3d0-4ff3-ae01-3f7b8cb19d79@[email protected]",
                    false);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"),
                    FileType.Audio,
                    "1142773b-44ba-410d-a56d-857783594434@---@QXBoZXggVHdpbiAtIFdpbmRvd2xpY2tlcg==.mp3",
                    false);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("eb9101dc-d7d4-4558-8211-cdd9fd9d60f9"),
                    FileType.Audio,
                    "89b0c1f5-c8b4-4929-b5a5-b065ff0883d8@---@QXBoZXggVHdpbiAtIE5hbm5vdQ==.mp3",
                    false);

                //// Squarepusher - Ultravisitor

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("4b3b4142-3621-4256-a209-4468a6c5ca4c"),
                    FileType.Image,
                    "4e192198-d5d0-4b3e-86dd-287814e2ee4a@[email protected]",
                    true);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("4b3b4142-3621-4256-a209-4468a6c5ca4c"),
                    FileType.Audio,
                    "3a7f690f-4a0e-4d54-9f13-d9857e1a5d1d@[email protected]",
                    false);

                //// Mobb Deep - Shook Ones

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("6eaabd12-fd4f-4b69-b0bd-f172f9b42085"),
                    FileType.Image,
                    "b37bfc94-df37-4d32-9bbd-0d6b36ce50c8@---@Ui02ODQwNjgtMTQ5MzY0OTc5Ny0zODc2LmpwZWc=.jpg",
                    true);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("6eaabd12-fd4f-4b69-b0bd-f172f9b42085"),
                    FileType.Image,
                    "86de218d-a345-4a74-a56a-835d5e435888@---@Ui02ODQwNjgtMTQ5MzY0OTc5OS05NzUzLmpwZWc=.jpg",
                    true);

                await SeedReleaseFileAsync(
                    dbContext,
                    Guid.Parse("6eaabd12-fd4f-4b69-b0bd-f172f9b42085"),
                    FileType.Audio,
                    "d682cea0-1bf6-4b3e-87e6-ced481e239bc@[email protected]",
                    false);
            }
        }