public static void SeedCourseParticipants(IServiceProvider serviceProvider) { var options = serviceProvider.GetRequiredService <DbContextOptions <LexiconLMSContext> >(); using (var context = new LexiconLMSContext(options)) { Course course = context.Courses.Include(c => c.Users).FirstOrDefault(c => c.Id == -1); if (course is null) { return; } if (course.Users != null && course.Users.Any()) { return; } var userManager = serviceProvider.GetRequiredService <UserManager <User> >(); var mapper = serviceProvider.GetRequiredService <IMapper>(); var config = serviceProvider.GetRequiredService <IConfiguration>(); var passwordForParticipants = (config["LexiconLMS:SeededCourse:ParticipantPW"] != null) ? config["LexiconLMS:SeededCourse:ParticipantPW"] : "secret123"; var localeCode = config["LexiconLMS:SeededCourse:LocaleCode"]; int.TryParse(config["LexiconLMS:SeededCourse:StudentsCount"], out int studentsCount); //Create students for (var i = 0; i < studentsCount; i++) { var bogusPerson = new Bogus.Person(localeCode); User student = mapper.Map <User>(bogusPerson); student.CourseId = course.Id; CreateUser(userManager, student, "Student", passwordForParticipants); } //CreateUser teacher User teacher = mapper.Map <User>(new Bogus.Person(localeCode)); teacher.CourseId = course.Id; CreateUser(userManager, teacher, "Teacher", passwordForParticipants); } }
public static void Initialize(IServiceProvider serviceProvider) { var options = serviceProvider.GetRequiredService <DbContextOptions <LexiconLMSContext> >(); using (var context = new LexiconLMSContext(options)) { try { if (context.ActivityType.Any()) { return; } // Let's seed! var ActivityTypes = new List <ActivityType>() { new ActivityType() { Type = "E-Learning" }, new ActivityType() { Type = "Lectures" }, new ActivityType() { Type = "Exercise" }, }; //people.Add(person); context.ActivityType.AddRange(ActivityTypes); context.SaveChanges(); } catch { //Table ActivityType should exist, but if it doesn't, don't crash the application completely. } } }
public TeacherController(LexiconLMSContext context, UserManager <User> userManager, IMapper mapper) { _context = context; _mapper = mapper; _userManager = userManager; }
public CourseController(LexiconLMSContext context, IMapper mapper, UserManager <User> userManager) { _context = context; _mapper = mapper; _userManager = userManager; }
public ModulesController(LexiconLMSContext context) { _context = context; }
public UsersController(LexiconLMSContext db) { this.db = db; }
public ModuleDocumentController(LexiconLMSContext context, IMapper mapper, UserManager <User> userManager) { _context = context; _mapper = mapper; _userManager = userManager; }
public CoursesController(LexiconLMSContext context) { _context = context; }
public ActivitiesController(LexiconLMSContext context) { _context = context; }
public ModuleController(LexiconLMSContext context, IMapper mapper) { _context = context; _mapper = mapper; }