private static async Task CreateStudentAsync(AsrContext context, string id, string name) { await context.Student.AddAsync(new Student { StudentID = id, Email = id + "@student.rmit.edu.au", Name = name }); }
private static async Task CreateStaffAsync(AsrContext context, string id, string name) { await context.Staff.AddAsync(new Staff { StaffID = id, Email = id + "@rmit.edu.au", Name = name }); }
public static async Task InitialiseAsync(IServiceProvider serviceProvider) { using (var userManager = serviceProvider.GetRequiredService <UserManager <User> >()) using (var roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >()) using (var context = new AsrContext(serviceProvider.GetRequiredService <DbContextOptions <AsrContext> >())) { await InitialiseUsersAsync(userManager, roleManager); await InitialiseAsrDataAsync(context, userManager); } }
private static async Task InitialiseAsrDataAsync(AsrContext context, UserManager <User> userManager) { // Look for any rooms. if (await context.Room.AnyAsync()) { return; // DB has been seeded. } await context.Room.AddRangeAsync( new Room { RoomID = "A" }, new Room { RoomID = "B" }, new Room { RoomID = "C" }, new Room { RoomID = "D" } ); await CreateStaffAsync(context, "e12345", "Matt"); await CreateStaffAsync(context, "e56789", "Matt"); await CreateStudentAsync(context, "s1234567", "Kevin"); await CreateStudentAsync(context, "s4567890", "Olivier"); await context.Slot.AddRangeAsync( new Slot { RoomID = "A", StartTime = new DateTime(2019, 1, 30), StaffID = "e12345" }, new Slot { RoomID = "B", StartTime = new DateTime(2019, 1, 30), StaffID = "e56789", StudentID = "s1234567" } ); await context.SaveChangesAsync(); await UpdateUserAsync(userManager, "*****@*****.**", "e12345"); await UpdateUserAsync(userManager, "*****@*****.**", "e56789"); await UpdateUserAsync(userManager, "*****@*****.**", "s1234567"); await UpdateUserAsync(userManager, "*****@*****.**", "s4567890"); }