Beispiel #1
0
        public string MakeStudentReport(string firstName, string lastName,
                                        Func <IEnumerable <Attendance>, string> serializer = null)
        {
            var students = _studentService.Find(s =>
                                                s.FirstName == firstName && s.LastName == lastName).ToList();

            if (students.Count == 0)
            {
                _logger?.LogWarning($"Entered student {firstName} {lastName} doesn't exist");
                throw new ValidationException($"Entered student {firstName} {lastName} doesn't exist");
            }

            if (serializer == null)
            {
                var jsonSerializer = new JsonAttendanceSerializer();
                serializer = jsonSerializer.Serialize;
            }

            var attendance = from student in students
                             from homework in student.StudentHomework
                             select new Attendance()
            {
                LectureName   = _lectureService.GetAsync(homework.LectureId).Result.Name,
                ProfessorName = $"{_professorService.GetAsync(_lectureService.GetAsync(homework.LectureId).Result.ProfessorId).Result.FirstName} " +
                                $"{_professorService.GetAsync(_lectureService.GetAsync(homework.LectureId).Result.ProfessorId).Result.LastName}",
                StudentName      = $"{student.FirstName} {student.LastName}",
                StudentPresence  = homework.StudentPresence,
                HomeworkPresence = homework.HomeworkPresence,
                Mark             = homework.Mark,
                Date             = homework.Date
            };

            return(serializer(attendance));
        }
Beispiel #2
0
        public string MakeLectureReport(string lectureName, Func <IEnumerable <Attendance>, string> serializer = null)
        {
            var lectures = _lectureService.Find(l => l.Name == lectureName).ToList();

            if (lectures.Count == 0)
            {
                _logger?.LogWarning($"Entered lecture {lectureName} doesn't exist");
                throw new ValidationException($"Entered lecture {lectureName} doesn't exist");
            }

            if (serializer == null)
            {
                var jsonSerializer = new JsonAttendanceSerializer();
                serializer = jsonSerializer.Serialize;
            }

            var attendance = from lecture in lectures
                             from homework in lecture.LectureHomework
                             select new Attendance()
            {
                LectureName   = lecture.Name,
                ProfessorName = $"{_professorService.GetAsync(lecture.ProfessorId).Result.FirstName} " +
                                $"{_professorService.GetAsync(lecture.ProfessorId).Result.LastName}",
                StudentName = $"{_studentService.GetAsync(homework.StudentId).Result.FirstName} " +
                              $"{_studentService.GetAsync(homework.StudentId).Result.LastName}",
                StudentPresence  = homework.StudentPresence,
                HomeworkPresence = homework.HomeworkPresence,
                Mark             = homework.Mark,
                Date             = homework.Date
            };

            return(serializer(attendance));
        }
Beispiel #3
0
        public IActionResult GetLectureReport(FileType type, string lectureName)
        {
            if (string.IsNullOrEmpty(lectureName))
            {
                return(BadRequest());
            }

            ISerializer serializer;

            switch (type)
            {
            case FileType.JSON:
            {
                serializer = new JsonAttendanceSerializer();
                break;
            }

            case FileType.XML:
            {
                serializer = new XmlAttendanceSerializer();
                break;
            }

            default:
                return(BadRequest());
            }

            var content = _reportService.MakeLectureReport(lectureName, serializer.Serialize);

            return(File(Encoding.UTF8.GetBytes(content),
                        System.Net.Mime.MediaTypeNames.Application.Json,
                        $"{DateTime.Now.ToShortDateString()} - {lectureName} Attendance {type}.txt"));
        }
Beispiel #4
0
        private static string MakeJsonReportData()
        {
            var attendance = new List <Attendance>()
            {
                new Attendance()
                {
                    LectureName      = "Math",
                    ProfessorName    = "Kirill Kononov",
                    StudentName      = "Kirill Kononov",
                    HomeworkPresence = true,
                    StudentPresence  = true,
                    Mark             = 4,
                    Date             = DateTime.Now
                }
            };
            var serializer = new JsonAttendanceSerializer();

            return(serializer.Serialize(attendance));
        }