public CourseTasks GetCourseTasks(int id) { var ct = new CourseTasks(); var course = db.Courses .Include(c => c.Organization) .FirstOrDefault(c => c.Id == id); if (course == null) { return(null); } var students = course.Students.Select(s => new User { Id = s.Id, Name = s.UserName }).ToList(); var tasks = course.Tasks; ct.Students = students; ct.Tasks = tasks; var studentTasks = new Dictionary <string, Dictionary <int, Score> >(); var scores = db.Scores.ToList(); foreach (var student in students) { studentTasks[student.Id] = new Dictionary <int, Score>(); foreach (var task in tasks) { var score = scores .FirstOrDefault(s => s.Task.Id == task.Id && s.Student.Id == student.Id); if (score == null) { studentTasks[student.Id][task.Id] = null; continue; } studentTasks[student.Id][task.Id] = new Score { Id = score.Id, Status = score.Status, Comments = score.Comments, Student = null, Task = null, Value = score.Value }; } } ct.UserTasks = studentTasks; return(ct); }
/// <summary> /// Creates a new <see cref="Course"/> instance. /// </summary> /// <param name="name">The name of the course.</param> protected Course(string name) { Name = name; TaskManager = new CourseTasks(); }