예제 #1
0
        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);
            }
        }
예제 #2
0
        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.
                }
            }
        }
예제 #3
0
 public TeacherController(LexiconLMSContext context, UserManager <User> userManager, IMapper mapper)
 {
     _context     = context;
     _mapper      = mapper;
     _userManager = userManager;
 }
예제 #4
0
 public CourseController(LexiconLMSContext context, IMapper mapper, UserManager <User> userManager)
 {
     _context     = context;
     _mapper      = mapper;
     _userManager = userManager;
 }
예제 #5
0
 public ModulesController(LexiconLMSContext context)
 {
     _context = context;
 }
예제 #6
0
 public UsersController(LexiconLMSContext db)
 {
     this.db = db;
 }
예제 #7
0
 public ModuleDocumentController(LexiconLMSContext context, IMapper mapper, UserManager <User> userManager)
 {
     _context     = context;
     _mapper      = mapper;
     _userManager = userManager;
 }
예제 #8
0
 public CoursesController(LexiconLMSContext context)
 {
     _context = context;
 }
예제 #9
0
 public ActivitiesController(LexiconLMSContext context)
 {
     _context = context;
 }
예제 #10
0
 public ModuleController(LexiconLMSContext context, IMapper mapper)
 {
     _context = context;
     _mapper  = mapper;
 }