public async Task <StatisticsViewModel> GetHistoriesForLector() { Lector lector = await AccountCredentials.GetLector(); IEnumerable <Discipline> disciplines = await(from ld in _context.LectorDisciplines join d in _context.Disciplines on ld.DisciplineId equals d.Id where ld.LectorId == lector.Id select d).ToListAsync(); IEnumerable <Lecture> lectures = (from d in disciplines join l in await _context.Lectures.ToListAsync() on d.Id equals l.DisciplineId select l).ToList(); IEnumerable <LecturesHistory> histories = (from l in lectures join h in await _context.LecturesHistories.ToListAsync() on l.Id equals h.LectureId select h).ToList(); StatisticsViewModel totalStatistics = new StatisticsViewModel { Lector = lector, Disciplines = disciplines, Lectures = lectures, Histories = histories }; return(totalStatistics); }
public async Task StartLecture(ReasignViewModel model) { var disc = model.Disciplines[0].Id; var lect = model.Lectures[0].Id; var date = DateTime.UtcNow; var lector = await AccountCredentials.GetLector(); var lectureHistory = _db.LecturesHistories.Add(new LecturesHistory { LectureId = lect, DisciplineId = disc, StartTime = date, IsFrozen = false, LectorId = lector.Id }); await _db.SaveChangesAsync(); _db.ModuleHistories.AddRange( from m in await _db.Modules.ToListAsync() where m.LectureId == lect select new ModuleHistory { IsPassed = false, LectureHistoryId = lectureHistory.Id, ModuleId = m.Id, StartTime = null, LectorId = lector.Id }); _db.LectureHistoryGroups.AddRange( from g in model.Groups where g.IsSelected select new LectureHistoryGroup { GroupId = g.Id, LectureHistoryId = lectureHistory.Id }); await _db.SaveChangesAsync(); }