示例#1
0
        public async Task <ActionResult <VenueDto> > AddVenueToLesson(
            [FromRoute] Guid classroomId,
            [FromRoute] Guid venueId,
            [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, "IsOwner");

                if (!authorization.Succeeded)
                {
                    return(Forbid());
                }

                var venue = await _venueService.FindAsync(venueId);

                var lesson = await _lessonService.FindAsync(lessonId);

                await _lessonService.AddVenueAsync(lesson, venue);

                return(Ok(venue.ToDto()));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(BadRequest());
            }
        }