public async Task<string> GetSchedulePracticeReportAsync(int month, int year) { int maxDaysInMonth = DateTime.DaysInMonth(year, month); DateTime date = new DateTime(year, month, maxDaysInMonth); var groups = await _context.Groups.FindAsync(g => g.PracticeStartDate <= date); List<Cadet> cadets = new List<Cadet>(); foreach (var g in groups) { foreach (var u in g.Cadets) { cadets.Add(u); } } List<SchedulePractice> schedulePractice = new List<SchedulePractice>(); foreach (var c in cadets) { foreach (var s in c.SchedulePractices) { schedulePractice.Add(s); } } //таким велосипедом получили все занятия которые проводятся в нужном месяце string path = string.Format("{0}Reports/{1}{2}{3}.pdf", _serverPath, "РасписаниеПрактическихЗанятий", month, year); if (File.Exists(path)) { File.Delete(path); } SchedulePracticeReport report = new SchedulePracticeReport(path) { Month = month, Year = year, }; List<SchedulePracticeEntity> lessons = new List<SchedulePracticeEntity>(); foreach (var less in schedulePractice.Select(s => s.DayOfWeek).Distinct()) { SchedulePracticeEntity entity = new SchedulePracticeEntity(); entity.DayOfWeek = less; entity.Dates = DaysOfMonth(month, year).Where(d => DayOfWeekRus(d) == less); List<LessonPracticeEntity> list = new List<LessonPracticeEntity>(); foreach (var item in schedulePractice.Where(s => s.DayOfWeek == less)) { LessonPracticeEntity l = new LessonPracticeEntity { StartTime = item.StartTime, EndTime = item.EndTime, Cadet = item.Cadet.Initials, Instructor = item.Instructor.Initials, }; list.Add(l); } entity.Practices = list; lessons.Add(entity); } report.Practices = lessons; return report.GetReport(); }
public static void ReportFour() { SchedulePracticeReport obj = new SchedulePracticeReport("D:\\new4.pdf"); List<SchedulePracticeEntity> list = new List<SchedulePracticeEntity> { new SchedulePracticeEntity { DayOfWeek = "Четверг", Dates = new List<DateTime> { new DateTime(2015, 10, 1), new DateTime(2015, 10, 8), }, Practices = new List<LessonPracticeEntity> { new LessonPracticeEntity { StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Иванов И. И.", Cadet = "Сидоров К. А.", }, }, }, new SchedulePracticeEntity { DayOfWeek = "Пятница", Dates = new List<DateTime> { new DateTime(2015, 10, 2), new DateTime(2015, 10, 9), }, Practices = new List<LessonPracticeEntity> { new LessonPracticeEntity { StartTime = new TimeSpan(18, 0, 0), EndTime = new TimeSpan(18, 45, 0), Instructor = "Иванов И. И.", Cadet = "Романович Л. А.", }, new LessonPracticeEntity { StartTime = new TimeSpan(14, 0, 0), EndTime = new TimeSpan(14, 45, 0), Instructor = "Пупкин В. В.", Cadet = "Петров П. П.", }, }, }, new SchedulePracticeEntity { DayOfWeek = "Понедельник", Dates = new List<DateTime> { new DateTime(2015, 10, 12), new DateTime(2015, 10, 5), }, Practices = new List<LessonPracticeEntity> { new LessonPracticeEntity { StartTime = new TimeSpan(17, 0, 0), EndTime = new TimeSpan(17, 45, 0), Instructor = "Иванов И. И.", Cadet = "Петров П. П.", }, }, }, new SchedulePracticeEntity { DayOfWeek = "Вторник", Dates = new List<DateTime> { new DateTime(2015, 10, 6), new DateTime(2015, 10, 13), }, Practices = new List<LessonPracticeEntity> { new LessonPracticeEntity { StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(16, 45, 0), Instructor = "Пупкин В. В.", Cadet = "Романович Л. А.", }, new LessonPracticeEntity { StartTime = new TimeSpan(18, 0, 0), EndTime = new TimeSpan(18, 45, 0), Instructor = "Иванов И. И.", Cadet = "Сидоров К. П.", }, }, }, new SchedulePracticeEntity { DayOfWeek = "Среда", Dates = new List<DateTime> { new DateTime(2015, 10, 7), }, Practices = new List<LessonPracticeEntity> { new LessonPracticeEntity { StartTime = new TimeSpan(16, 0, 0), EndTime = new TimeSpan(16, 45, 0), Instructor = "Пупкин В. В.", Cadet = "Романович Л. А.", }, }, }, new SchedulePracticeEntity { DayOfWeek = "Суббота", Dates = new List<DateTime> { new DateTime(2015, 10, 10), new DateTime(2015, 10, 3), }, Practices = new List<LessonPracticeEntity> { new LessonPracticeEntity { StartTime = new TimeSpan(15, 0, 0), EndTime = new TimeSpan(15, 45, 0), Instructor = "Пупкин В. В.", Cadet = "Сидоров К. А.", }, }, }, }; obj.Practices = list; obj.Month = 10; obj.Year = 2015; Console.WriteLine(obj.GetReport()); }