public async Task <ActionResult> CreateChat(CreateChatCommand request) { request.UserId = CurrentUserService.UserId; var chatId = await Mediator.Send(request); return(Ok(chatId)); }
private ICommand CreateChatCreationCommand() { var command = new CreateChatCommand( this.ninjectKernel.Get <IServerChatService>()); return(command); }
public async Task WhenNoNameProvided_ThrowsBadRequestException() { var user = await RunAsDefaultUserAsync(); var request = new CreateChatCommand { Name = string.Empty, UserId = user.Id }; await FluentActions.Invoking(async() => await SendAsync(request)).Should().ThrowAsync <BadRequestException>(); }
public ActionResult CreateChat(CreateChatCommand command) { string message; User user; ChatRoom room; if ((user = _repository.GetUserByToken(command.user_token)) != null) { var opposideUser = _repository.GetUserByPublicToken(command.opposide_public_token); if (opposideUser != null) { var participant = _repository.GetParticipantByIds(user.Id, opposideUser.Id); if (participant == null) { room = new ChatRoom { Token = _profileCondition.GenerateHash(20), CreatedAt = DateTimeOffset.UtcNow }; room = _repository.CreateChatRoom(room); var userParticipant = new Participant { ChatId = room.Id, UserId = user.Id, OpposideId = opposideUser.Id }; var opposideParticipant = new Participant { ChatId = room.Id, UserId = opposideUser.Id, OpposideId = user.Id }; _repository.CreateParticipant(userParticipant); _repository.CreateParticipant(opposideParticipant); _logger.LogInformation($"Create chat for user, id -> {user.Id} & opposide, id -> {opposideUser.Id}."); } else { room = _repository.GetChatById(participant.ChatId); _logger.LogInformation($"Select exist chat for user, id -> {user.Id} & opposide, id -> {opposideUser.Id}."); } return(Ok(new ChatRoomDto(room))); } else { message = "Server can't define interlocutor by token."; } } else { message = "Server can't define user by token."; } _logger.LogWarning(message); var response = new MessageResponse(false, message); return(StatusCode(500, response)); }
void Ready() { Context.System.EventStream.Subscribe(Self, typeof(UserRegisteredEvent)); Context.System.EventStream.Subscribe(Self, typeof(SubscribedToUserEvent)); Receive <RegisterModel>(register => { var command = new RegisterUserCommand(register.UserId, register.Login, register.UserName); var envelope = new ShardEnvelope(command.Id.ToString(), command); UserRegion.Tell(envelope); }); Receive <CreateChatModel>(x => { var command = new CreateChatCommand(x.ChatId, x.UserId, new List <Guid> { x.UserId, x.TargetUserId }); var envelope = new ShardEnvelope(command.Id.ToString(), command); ChatRegion.Tell(envelope); }); Receive <UserRegisteredEvent>(evt => { SignalrPusher.PlayerJoined(evt.Id, evt.Login, evt.UserName); }); Receive <SubscribeToUserCommand>(mes => { var envelope = new ShardEnvelope(mes.UserId.ToString(), mes); UserRegion.Tell(envelope); }); Receive <SubscribedToUserEvent>(mes => { SignalrPusher.UserAddedToContactList(mes.UserId, mes.ContactUserId, mes.ContactName); }); Receive <AddMessageToChatCommand>(cmd => { var envelope = new ShardEnvelope(cmd.ChatId.ToString(), cmd); ChatRegion.Tell(envelope); }); Receive <MarkChatMessagesReadCommand>(cmd => { var envelope = new ShardEnvelope(cmd.UserId.ToString(), cmd); UserRegion.Tell(envelope); }); }
public async Task <IActionResult> CreateChat([FromBody] CreateChatCommand createChatCommand) { var authHelper = new AuthHelperBuilder() .AllowSystem() .RequireId(createChatCommand.OwnerId) .RequirePermissions("chats.create") .Build(); if (!authHelper.Authorize(_identityService)) { return(Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(new ErrorResponse(ModelState))); } var chatDto = await _mediator.Send(createChatCommand); var url = Url.Action(nameof(GetChatById), new { id = chatDto.Id }); return(Created(url, chatDto)); }