Example #1
0
        public async Task <ActionResult <IEnumerable <UserDto> > > GetVenue(
            [FromRoute] Guid classroomId,
            [FromRoute] Guid lessonId
            )
        {
            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 lesson = await _lessonService.FindAsync(lessonId);

                await _lessonService.LoadVenueAsync(lesson);

                return(Ok(lesson.Venue is null ? new Venue().ToDto() : lesson.Venue.ToDto()));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }