public async Task<IEnumerable<ScheduleTheoryEntity>> GetSheduleTheoryAsync(int groupId) { var group = await _context.Groups.GetAsync(groupId); if (group != null) { var sched = await _context.ScheduleTheories.FindAsync(s => s.GroupId == groupId); if (sched.Count() > 0) { var shedule = new List<ScheduleTheoryEntity>(); foreach (var d in sched.Select(d => d.DayOfWeek).ToList().Distinct()) { ScheduleTheoryEntity entity = new ScheduleTheoryEntity(); entity.DayOfWeek = d; entity.Dates = new List<DateTime>(); DateTime startDate = group.TheoryStartDate; DateTime endDate = group.TheoryEndDate; for (DateTime i = startDate; i <= endDate; i = i.AddDays(1)) { if (DayOfWeekRus(i) == d) { ((List<DateTime>)entity.Dates).Add(i); } } entity.Lessons = new List<LessonTheoryEntity>(); foreach (var lesson in sched.Where(l => l.DayOfWeek == d)) { var gr = await _context.Groups.GetAsync(lesson.GroupId); var instr = await _context.Instructors.GetAsync(lesson.InstructorId); var less = new LessonTheoryEntity { Id = lesson.Id, StartTime = lesson.StartTime, EndTime = lesson.EndTime, Group = gr.GroupName, Instructor = instr.Initials, }; ((List<LessonTheoryEntity>)entity.Lessons).Add(less); } shedule.Add(entity); } return shedule; } } return null; }
public async Task<string> GetScheduleTheoryReportAsync(int month, int year) { int maxDaysInMonth = DateTime.DaysInMonth(year, month); DateTime date = new DateTime(year, month, maxDaysInMonth); var schedule = await _context.ScheduleTheories.FindAsync(s => s.Group.TheoryStartDate <= date); string path = string.Format("{0}Reports/{1}{2}{3}.pdf", _serverPath, "РасписаниеТеоритическихЗанятий", month, year); if (File.Exists(path)) { File.Delete(path); } ScheduleTheoryReport report = new ScheduleTheoryReport(path) { Month = month, Year = year, }; List<ScheduleTheoryEntity> lessons = new List<ScheduleTheoryEntity>(); foreach (var less in schedule.Select(s => s.DayOfWeek).Distinct()) { ScheduleTheoryEntity entity = new ScheduleTheoryEntity(); entity.DayOfWeek = less; entity.Dates = DaysOfMonth(month, year).Where(d => DayOfWeekRus(d) == less); List<LessonTheoryEntity> list = new List<LessonTheoryEntity>(); foreach (var item in schedule.Where(s => s.DayOfWeek == less)) { LessonTheoryEntity l = new LessonTheoryEntity { StartTime = item.StartTime, EndTime = item.EndTime, Group = item.Group.GroupName, Instructor = item.Instructor.Initials, }; list.Add(l); } entity.Lessons = list; lessons.Add(entity); } report.Lessons = lessons; return report.GetReport(); }