Exemplo n.º 1
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));
        }
Exemplo n.º 2
0
        public async Task <ActionResult <LectureDTO> > Put(LectureViewModel lectureViewModel)
        {
            if (lectureViewModel == null)
            {
                return(BadRequest());
            }

            if (!_db.Find(l => l.Id == lectureViewModel.Id).Any())
            {
                return(NotFound());
            }

            var lecture = _mapper.Map <LectureDTO>(lectureViewModel);
            await _db.UpdateAsync(lecture);

            return(Ok(lectureViewModel));
        }