public async Task <demoResult> CallBackToApplicant([FromBody] CallBackToApplicantDto model) { if (model.CaseFolderId == default) { _logger.Warning("Id инцидента не задан"); return(BadRequest(ErrorCodes.ValidationError)); } var result = await _callManagementService.CallBackToApplicant(GetUserId(), model); if (result.IsFailure) { _logger.Warning($"Ошибка при перезвоне заявителю. {result.ErrorMessage}"); return(BadRequest(result.ErrorCode)); } if (result.Value == CallBackToApplicantStatus.AlreadyInCall) { _logger.Warning("Ошибка при перезвоне заявителю. Заявитель уже участвует в звонке."); return(BadRequest(ErrorCodes.CallBackToApplicantAlreadyInCall)); } return(Ok()); }
/// <summary> /// Перезвонить заявителю /// </summary> public async Task <Result <CallBackToApplicantStatus> > CallBackToApplicant(Guid userId, CallBackToApplicantDto model) { using (_unitOfWork.Begin()) { var caseFolderId = model.CaseFolderId; CaseFolder caseFolder = await _caseFolderRepository.GetById(caseFolderId); if (caseFolder == null) { _logger.Warning($"CaseFolder with Id {caseFolderId} not found"); return(Result.Failure <CallBackToApplicantStatus>(ErrorCodes.CaseFolderNotFound)); } var participantResult = await GetApplicant(caseFolder); if (participantResult.IsFailure) { _logger.Warning(participantResult.ErrorMessage); return(Result.Failure <CallBackToApplicantStatus>(participantResult.ErrorCode)); } Result <UserClientDto> userResult = await _userManagementServiceClient.GetUserById(userId); if (userResult.IsFailure) { _logger.Warning($"CallBackToApplicant. Error get user by Id. {userResult.ErrorMessage}"); return(Result.Failure(ErrorCodes.UserNotFound)); } var user = _mapper.Map <UserDto>(userResult.Value); var clientModel = new CallBackToApplicantClientDto { UserExtension = user.Extension, ParticipantExtension = participantResult.Value.ParticipantExtension, CaseFolderId = caseFolderId, }; var result = await _callManagementServiceClient.CallBackToApplicant(clientModel); if (result.IsFailure) { _logger.Warning($"CallBackToApplicant. {result.ErrorMessage}"); return(Result.Failure <CallBackToApplicantStatus>(ErrorCodes.UnableToCallBackToApplicant)); } await _unitOfWork.CommitAsync(); await _phoneHubMessageService.NotifyUserAboutStartedExternalCall(userId, result.Value.LineId); return(Result.Success(CallBackToApplicantStatus.Ok)); } }