/// <summary>
        /// Получение карточки по Id инцидента
        /// </summary>
        public async Task <Result <CaseDto> > GetCaseByCaseFolderIdAsync(Guid caseFolderId, Guid userId)
        {
            using (_unitOfWork.Begin())
            {
                var caseFolder = await _caseFolderRepository.GetById(caseFolderId);

                if (caseFolder == null)
                {
                    _logger.Warning($"CaseFolder with Id {caseFolderId} not found");
                    return(Result.Failure <CaseDto>(ErrorCodes.CaseFolderNotFound));
                }

                Result <UserClientDto> result = await _userManagementServiceClient.GetUserById(userId);

                if (result.IsFailure)
                {
                    _logger.Warning($"User with Id {userId} not found");
                    return(Result.Failure <CaseDto>(ErrorCodes.UserNotFound));
                }

                var user = _mapper.Map <UserDto>(result.Value);

                Result <Case> userCaseCard = caseFolder.GetCaseForUser(user.Id);
                if (userCaseCard.IsFailure)
                {
                    _logger.Warning(userCaseCard.ErrorMessage);
                    return(Result.Failure <CaseDto>(userCaseCard.ErrorCode));
                }

                await NotifyGisFacadeAboutNewApplicantLocation(caseFolder, userId);

                return(Result.Success(CaseDto.MapFromCaseEntity(userCaseCard.Value)));
            }
        }
        /// <summary>
        /// Получить пользователя по Id
        /// </summary>
        public async Task <Result <UserDto> > GetUserById(Guid userId)
        {
            Result <UserClientDto> result = await _userManagementServiceClient.GetUserById(userId);

            if (result.IsFailure)
            {
                _logger.Warning($"GetUserById. Error get user by Id. {result.ErrorMessage}");
                return(Result.Failure <UserDto>(ErrorCodes.UserNotFound));
            }

            var dtoModel = _mapper.Map <UserDto>(result.Value);

            Result <List <CallClientDto> > callsResult = await _callManagementServiceClient.GetActualUserCalls();

            if (callsResult.IsFailure)
            {
                _logger.Warning($"GetUserInfo. Error getting information about actual user calls. UserId: {userId}. {callsResult.ErrorMessage}");
            }
            else
            {
                var activeCall = _mapper.Map <CallDto>(callsResult.Value?.FirstOrDefault());
                if (activeCall != null)
                {
                    dtoModel.SetCurrentCallStates(activeCall);
                }
            }

            return(Result.Success(dtoModel));
        }
Esempio n. 3
0
        private async Task <Participant> GetParticipant(Guid participantId)
        {
            var user = await _userManagementServiceClient.GetUserById(participantId);

            if (user.IsSuccess && user.Value != null)
            {
                var userClientDto = user.Value;
                return(new User(userClientDto.Id, userClientDto.Extension, $"{userClientDto.FirstName} {userClientDto.LastName}"));
            }

            var participant = await _participantRepository.GetById(participantId);

            return(participant);
        }
        /// <summary>
        /// Принять элемент из очереди (например, звонок или смс)
        /// </summary>
        public async Task <Result> AcceptInboxItem(Guid userId, Guid inboxId, Guid?itemId)
        {
            _logger.Verbose($"AcceptInboxItem. InboxId: {inboxId}; ItemId: {itemId}");

            _unitOfWork.Begin();

            Result <UserItemClientDto> userItemResult = await GetUserItem(inboxId, itemId);

            if (userItemResult.IsFailure)
            {
                _logger.Warning($"Failed to get userItem by id {inboxId}. {userItemResult.ErrorMessage}");
                return(Result.Failure(ErrorCodes.UnableToGetInbox));
            }

            Result <UserClientDto> currentUserResult = await _userManagementServiceClient.GetUserById(userId);

            if (currentUserResult.IsFailure)
            {
                _logger.Warning($"GetUserById. Error get user by Id. {currentUserResult.ErrorMessage}");
                return(Result.Failure(ErrorCodes.UserNotFound));
            }

            var currentUser = _mapper.Map <UserDto>(currentUserResult.Value);

            var userItem = userItemResult.Value;

            Result acceptResult;

            if (userItem.ItemType == ClientInboxItemType.Sms)
            {
                acceptResult = await ProcessSms(currentUser, userItem);
            }
            else
            {
                acceptResult = await ProcessCall(currentUser, userItem);
            }

            await _phoneHubMessageService.NotifyUsersAboutInboxUpdate(inboxId);

            return(acceptResult);
        }