예제 #1
0
        public async Task <IActionResult> HandleConsultationRequestAsync(PrivateConsultationRequest request)
        {
            var conference = await GetConference(request.ConferenceId);

            var requestedBy = conference.Participants?.SingleOrDefault(x => x.Id == request.RequestedById);

            if (requestedBy == null)
            {
                return(NotFound());
            }

            var requestedFor = conference.Participants?.SingleOrDefault(x => x.Id == request.RequestedForId);

            if (requestedFor == null)
            {
                return(NotFound());
            }

            var requestRaised = !request.Answer.HasValue;

            if (requestRaised)
            {
                await NotifyConsultationRequestAsync(conference, requestedBy, requestedFor);
            }
            else if (request.Answer == ConsultationAnswer.Cancelled)
            {
                await NotifyConsultationCancelledAsync(conference, requestedBy, requestedFor);
            }
            else
            {
                await NotifyConsultationResponseAsync(conference, requestedBy, requestedFor, request.Answer.Value);
            }

            try
            {
                var mappedRequest = PrivateConsultationRequestMapper.MapToApiConsultationRequest(request);
                await _videoApiClient.HandleConsultationRequestAsync(mappedRequest);

                return(NoContent());
            }
            catch (VideoApiException e)
            {
                object value;
                if (e is VideoApiException <ProblemDetails> )
                {
                    var errors =
                        Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string[]> >(e.Response);
                    value = BadRequestResponseMapper.MapToResponse(errors);
                    await NotifyParticipantsConsultationRoomOccupied(request.ConferenceId, requestedBy.Username,
                                                                     requestedFor.Username);
                }
                else
                {
                    value = e.Response;
                }

                _logger.LogError(e, $"Consultation error ConferenceId: {request.ConferenceId} and answer {request.Answer}, ErrorCode: {e.StatusCode}");
                return(StatusCode(400, value));
            }
        }
        public void should_map_dictionary_to_response()
        {
            var title      = "ConsultationRoom";
            var errorArray = new[] { "No consultation room available" };
            var errors     = new Dictionary <string, string[]> {
                { title, errorArray }
            };

            var result = BadRequestResponseMapper.MapToResponse(errors);

            result.Errors[0].Title.Should().BeEquivalentTo(title);
            result.Errors[0].Errors.Should().BeEquivalentTo(errorArray);
        }