public void Update(DatabaseContext context, IConfiguration config, Lecture previous) { UpdateDirectory(context, config, previous); // reset repositories if (previous.Name != Name) { LectureContentsRepositoryPair.ResetRemoteUrl(); LectureSubmissionsRepositoryPair.ResetRemoteUrl(); } // parse teachers and students var flts = context.Users.Select(x => x.Account); var newTeachers = TeachersForEdit?.Split(' ', ',', '\t', '\n', '\r') ?? new string[0] { }; var newStudents = StudentsForEdit?.Split(' ', ',', '\t', '\n', '\r')?.Except(newTeachers) ?? new string[0] { }; var teachers = GetTeachers().Select(x => x.Account); var students = GetStudents().Select(x => x.Account); foreach (var user in context.Users) { if (newTeachers.Contains(user.Account) && !teachers.Contains(user.Account)) { var a = new LectureUser() { Lecture = this, User = user, Role = LectureUserRole.Teacher }; LectureUsers.Add(a); a.CreateNew(context, config); } if (!newTeachers.Contains(user.Account) && teachers.Contains(user.Account)) { var a = LectureUsers.Where(x => x.UserId == user.Id && x.LectureId == Id && x.Role == LectureUserRole.Teacher).FirstOrDefault(); LectureUsers.Remove(a); a.Remove(context, config); } if (newStudents.Contains(user.Account) && !students.Contains(user.Account)) { var a = new LectureUser() { Lecture = this, User = user, Role = LectureUserRole.Student }; LectureUsers.Add(a); a.CreateNew(context, config); } if (!newStudents.Contains(user.Account) && students.Contains(user.Account)) { var a = LectureUsers.Where(x => x.UserId == user.Id && x.LectureId == Id && x.Role == LectureUserRole.Student).FirstOrDefault(); LectureUsers.Remove(a); a.Remove(context, config); } } var me = GetEntityForEditOrRemove(context, config); foreach (var x in me.LectureUsers) { x.UpdateParent(context, config, this, previous); } foreach (var x in me.Sandboxes) { x.UpdateParent(context, config, this, previous); } context.Update(this); }
public IEnumerable <User> GetTeachers() { return(LectureUsers.Where(x => x.Role == LectureUserRole.Teacher).Select(x => x.User)); }
public IEnumerable <User> GetStudents() { return(LectureUsers.Where(x => x.Role == LectureUserRole.Student).Select(x => x.User)); }