private void AppendLabsPackModel(Pack pack, PackViewModel packViewModel) { var actualWorks = pack.WorkProcs.Where(l => l.CurrentValue.State == 0).ToList(); foreach (var wp in actualWorks) { Work work = db.Works.Find(wp.WorkId); string workTitle = work.ShortName; packViewModel.Header.Items.Add(new Item() { Id = wp.Id, Title = workTitle, Span = work.HasThemes ? 2 : 1, Type = 1 }); } var group = pack.Groups[0]; var students = group.Students.OrderBy(s => s.Surname).ToList(); foreach (var student in students) { var studentRow = packViewModel.Rows.First(r => r.Item.Id == student.Id); foreach (var workProc in actualWorks) { StudentWorkProc studentWorkProc = workProc.GetStudentWorkProc(student); if(studentWorkProc == null) { studentRow.Items.Add(new Item() { Id = 0, Type = -1 }); continue; } Work work = db.Works.Find(studentWorkProc.WorkProc.WorkId); if (work.HasThemes) { string themeName; if (studentWorkProc.CurrentValue.WorkThemeId != null) { themeName = db.WorkThemes.Find(studentWorkProc.CurrentValue.WorkThemeId).Name; } else { themeName = "Нет темы"; } studentRow.Items.Add(new Item() { Id = studentWorkProc.Id, Type = 2, Title = themeName }); } studentRow.Items.Add(new Item() { Id = studentWorkProc.Id, Type = 1, Title = GetStudentWorkProcTitle(studentWorkProc), Progress = GetStudentWorkProcProgress(studentWorkProc) }); } } }
private PackViewModel CreateLessonsPackModel(Pack pack, int groupIndex, string titleString) { var title = new Item() { Title = titleString }; PackViewModel packViewModel = null; var actualLessons = pack.Lessons.Where(l => l.CurrentValue.State == 0).OrderBy(l => l.Date).ToList(); var headerItems = actualLessons.Select(l => new Item() { Id = l.Id, Title = GetLessonTitle(l), Type = 0 }).ToList(); var header = new Header() { Items = headerItems }; //init rows List<Row> rows = new List<Row>(); var group = pack.Groups[groupIndex]; var students = group.Students.OrderBy(s => s.Surname).ToList(); foreach (var student in students) { string studentTitle = GetStudentTitle(student); var studentRow = new Row() { Item = new Item() { Id = student.Id, Title = studentTitle }, Items = new List<Item>() }; foreach (var lesson in actualLessons) { Visit visit = lesson.GetVisitForStudent(student); //todo: предусмотреть возможность отсутствия посещения как такового if (visit != null) { studentRow.Items.Add(new Item() { Id = visit.Id, Title = GetVisitTitle(visit), Value = (int)visit.CurrentValue.Value }); } else { studentRow.Items.Add(new Item() { Id = 0, Type = -1 }); } } rows.Add(studentRow); } packViewModel = new PackViewModel() { Title = title, Header = header, Rows = rows }; return packViewModel; }