public async Task <ActionResult <IEnumerable <LessonDto> > > GetLessons( [FromRoute] Guid classroomId ) { var user = (ApplicationUser)HttpContext.Items["ApplicationUser"]; Debug.Assert(user != null, nameof(user) + " != null"); try { var classroom = await _classroomService.FindAsync(classroomId); var authorization = await _authorizationService.AuthorizeAsync(User, classroom, "IsInClassroom"); if (!authorization.Succeeded) { return(Forbid()); } var lessons = await _lessonService.FindByClassroomAsync(classroomId); lessons = await Task.WhenAll(lessons.Select(async l => await _lessonService.LoadTeachersAsync(l))); var lessonDtos = lessons.Select(l => l.ToDto()); return(Ok(lessonDtos)); } catch (Exception e) { Console.WriteLine(e); return(BadRequest()); } }