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