private static void SeedDefaultVideoIndexStatuses(FairplaytubeDatabaseContext fairplaytubeDatabaseContext, Common.Global.Enums.VideoIndexStatus videoIndexStatus) { var videoIndexStatusEntity = fairplaytubeDatabaseContext.VideoIndexStatus .SingleOrDefault(p => p.Name == videoIndexStatus.ToString()); if (videoIndexStatusEntity == null) { videoIndexStatusEntity = new VideoIndexStatus() { Name = videoIndexStatus.ToString(), VideoIndexStatusId = (short)videoIndexStatus }; fairplaytubeDatabaseContext.VideoIndexStatus.Add(videoIndexStatusEntity); fairplaytubeDatabaseContext.SaveChanges(); } }
private static void SeedDefaultCultures(FairplaytubeDatabaseContext fairplaytubeDatabaseContext, string cultureName, int cultureId) { var cultureEntity = fairplaytubeDatabaseContext.Culture .SingleOrDefault(p => p.Name == cultureName); if (cultureEntity == null) { cultureEntity = new Culture() { CultureId = cultureId, Name = cultureName }; fairplaytubeDatabaseContext.Culture.Add(cultureEntity); fairplaytubeDatabaseContext.SaveChanges(); } }
private static void SeedDefaultVideoVisibility(FairplaytubeDatabaseContext fairplaytubeDatabaseContext, Common.Global.Enums.VideoVisibility visibility) { var visibilityEntity = fairplaytubeDatabaseContext.VideoVisibility .SingleOrDefault(p => p.Name == visibility.ToString()); if (visibilityEntity == null) { visibilityEntity = new VideoVisibility() { VideoVisibilityId = (short)visibility, Name = visibility.ToString() }; fairplaytubeDatabaseContext.Add(visibilityEntity); fairplaytubeDatabaseContext.SaveChanges(); } }
private static void SeedDefaultRoles(FairplaytubeDatabaseContext fairplaytubeDatabaseContext, short roleId, string roleName) { var roleEntity = fairplaytubeDatabaseContext.ApplicationRole .SingleOrDefault(p => p.Name == roleName); if (roleEntity == null) { roleEntity = new ApplicationRole() { ApplicationRoleId = roleId, Name = roleName, Description = roleName }; fairplaytubeDatabaseContext.ApplicationRole.Add(roleEntity); fairplaytubeDatabaseContext.SaveChanges(); } }
private static void ConfigureInMemoryDatabase(FairplaytubeDatabaseContext fairplaytubeDatabaseContext) { fairplaytubeDatabaseContext.Database.EnsureCreated(); SeedDefaultCultures(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, cultureName: "en-US", cultureId: 1); SeedDefaultRoles(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, roleId: 1, roleName: Common.Global.Constants.Roles.User); SeedDefaultRoles(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, roleId: 2, roleName: Common.Global.Constants.Roles.Admin); fairplaytubeDatabaseContext.SaveChanges(); SeedDefaultVideoIndexStatuses(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, videoIndexStatus: Common.Global.Enums.VideoIndexStatus.Pending); SeedDefaultVideoIndexStatuses(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, videoIndexStatus: Common.Global.Enums.VideoIndexStatus.Processing); SeedDefaultVideoIndexStatuses(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, videoIndexStatus: Common.Global.Enums.VideoIndexStatus.Processed); SeedDefaultVideoIndexStatuses(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, videoIndexStatus: Common.Global.Enums.VideoIndexStatus.Deleted); SeedDefaultVideoVisibility(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, visibility: Common.Global.Enums.VideoVisibility.Public); SeedDefaultVideoVisibility(fairplaytubeDatabaseContext: fairplaytubeDatabaseContext, visibility: Common.Global.Enums.VideoVisibility.Private); }