Beispiel #1
0
        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();
            }
        }
Beispiel #2
0
 public ModuleRepository(LmsApiContext db)
 {
     this.db = db;
 }
Beispiel #3
0
 public CourseRepository(LmsApiContext db)
 {
     this.db = db;
 }
Beispiel #4
0
 public UoW(LmsApiContext db)
 {
     this.db          = db;
     CourseRepository = new CourseRepository(db);
     ModuleRepository = new ModuleRepository(db);
 }