public async Task <ActionResult> Create([FromBody] ChatRoomCreationRequestDTO chatRoomCreationRequestDTO) { _logger.LogInformation($"New chat room request: {chatRoomCreationRequestDTO}"); var validator = new ChatRoomCreationValidator(); var validationResult = validator.Validate(chatRoomCreationRequestDTO); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } try { var result = await _chatRoomService.CreateChatRoom(chatRoomCreationRequestDTO); return(StatusCode(201, result)); } catch (ObjectAlreadyExistsException e) { return(BadRequest(new ServiceErrorDTO { Message = e.Message })); } }
public async Task CreateChatRoom(CreateChatRoomRequest roomRequest) { try { var room = _chatRoomService.CreateChatRoom(roomRequest.UserCreatorId, roomRequest.UserInvitedId, roomRequest.Name); var result = _mapper.Map <ChatRoomModel>(room); // create group await this.Groups.AddToGroupAsync(this.Context.ConnectionId, room.Id.ToString()); //3. return room id to those tow users await this.Clients.Caller.ChatRoomCreated(result); var invitedUserConnected = _userConnectionService.GetConnectionForUser(roomRequest.UserInvitedId); if (invitedUserConnected != null) { await this.Groups.AddToGroupAsync(invitedUserConnected.ConnectionId, room.Id.ToString()); await this.Clients.Client(invitedUserConnected.ConnectionId).ChatRoomCreated(result); } } catch (Exception ex) { throw; } }
public ActionResult CreateChatRoom(string userId) { string currentUserId = User.Identity.GetUserId(); string[] usersId = new string[] { currentUserId, userId }; _chatRoomService.CreateChatRoom(usersId); _notificationService.CreateNotification(currentUserId, userId, "You invited to chat room"); _commitProvider.SaveChanges(); _notificationService.RefreshNotifications(userId); return(ChatRooms()); }