Example #1
0
        public IActionResult AddUser(uint chatId, [FromQuery][BindRequired] string username)
        {
            var userToAdd  = _userService.FindUser(username);
            var chatMember = _chatService.AddUserToChat(User.Identity.Name, chatId, userToAdd);

            return(new JsonResult(chatMember));
        }
Example #2
0
        public async Task <IActionResult> AddUserToChat(string chatId, string userId)
        {
            var result = await chatService.AddUserToChat(userId, chatId);

            if (result.IsSuccessed)
            {
                return(Ok(result.Result));
            }

            return(BadRequest(result.ErrorMessage));
        }
Example #3
0
        public async Task AddUserToChat(int chatId, int userId)
        {
            await _chatService.AddUserToChat(chatId, userId, this.UserId);

            _usersConnections.GetOrAdd(userId, new HashSet <string>()).ForEach(async connId =>
            {
                _chatsConnections[chatId].Add(connId);
                await Groups.AddToGroupAsync(connId, chatId.ToString());
            });

            await Clients.Group(chatId.ToString()).SendAsync("AddUserToChat", userId, chatId);
        }
 public IHttpActionResult UserToChat(string userId, int chatId)
 {
     try
     {
         service.AddUserToChat(userId, chatId);
         return(Ok());
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
        public IHttpActionResult AddUserToChat(int chatId, [FromBody] string userToAddId)
        {
            var user      = _userService.GetById(RequestContext.Principal.Identity.GetUserId());
            var chat      = _chatService.GetById(chatId);
            var userToAdd = _userService.GetById(userToAddId);

            if (chat == null || userToAdd == null)
            {
                return(NotFound());
            }
            if (chat.Users.FirstOrDefault(u => u.Id == user.Id) == null && !RequestContext.Principal.IsInRole("Moderator"))
            {
                return(StatusCode(HttpStatusCode.Forbidden));
            }

            _chatService.AddUserToChat(chat.Id, userToAdd.Id);
            return(Ok());
        }