public static async Task InitAsync(IServiceProvider services) { //Part 2 regarding seeding using (var context = new LmsApiContext (services.GetRequiredService <DbContextOptions <LmsApiContext> >())) { if (await context.Course.AnyAsync()) { return; } var fake = new Faker("sv"); var courses = new List <Course>(); var modules = new List <Module>(); for (int i = 0; i < 20; i++) { var course = new Course { Title = fake.Company.CatchPhrase(), StartDate = DateTime.Now.AddDays(fake.Random.Int(-2, 2)), }; courses.Add(course); } await context.AddRangeAsync(courses); foreach (Course course in courses) { var module = new Module { Course = course, Title = fake.Company.CatchPhrase(), StartDate = DateTime.Now.AddDays(fake.Random.Int(-2, 2)) }; modules.Add(module); } await context.AddRangeAsync(modules); await context.SaveChangesAsync(); } }
public ModuleRepository(LmsApiContext db) { this.db = db; }
public CourseRepository(LmsApiContext db) { this.db = db; }
public UoW(LmsApiContext db) { this.db = db; CourseRepository = new CourseRepository(db); ModuleRepository = new ModuleRepository(db); }