示例#1
0
        public async Task <IActionResult> ConnectToChat([FromBody] ConnectChatDto connectChatDto)
        {
            var userId = this.User.Claims.First(c => c.Type == "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value;

            try
            {
                await _chatService.AddUserToChatAsync(connectChatDto, userId);

                return(Ok(ChatControllerConstants.YouAreAddedToChat));
            } catch (Exception ex)
            {
                _logger.Error(ex);
                return(StatusCode(StatusCodes.Status500InternalServerError, ex.InnerException.Message));
            }
        }
示例#2
0
        public async Task AddUserToChatAsync(ConnectChatDto connectChatDto, string userId)
        {
            var chat = await _unitOfWork.ChatRepository.GetByIdAsync(connectChatDto.Id);

            if (chat == null || !chat.Public)
            {
                throw new ArgumentException("Chat with this is not exist or you can't connect to this chat");
            }

            await _unitOfWork.UserChatRepository.AddAsync(new UserChat
            {
                ChatId = chat.Id,
                UserId = userId
            });

            await _unitOfWork.CommitAsync();
        }