public async Task AddPlayer(HubCallerContext context, IGroupManager groups, HttpContext httpContext) { if (IsGameRunning) { await Clients.Client(context.ConnectionId).InvokeAsync("Reject", players); await groups.RemoveAsync(context.ConnectionId, PlayingGroup); await groups.AddAsync(context.ConnectionId, WaitlistGroup); } else if (players.TrueForAll(p => p.ConnectionId != context.ConnectionId)) { await groups.RemoveAsync(context.ConnectionId, WaitlistGroup); await groups.AddAsync(context.ConnectionId, PlayingGroup); lock (playersLock) { players.Add(new Player { ConnectionId = context.ConnectionId, IpAddress = httpContext.Connection.RemoteIpAddress.ToString(), Username = DbContext.GetUsername(GopUser.GetCurrentUser(httpContext)), Run = true, IsWatching = true, StartLocation = DefaultStartingLocations[Math.Min(DefaultStartingLocations.Length - 1, players.Count)] }); } await Clients.Client(context.ConnectionId).InvokeAsync("SetGameParams", Altar, Seed); await PlayingClients.UpdatePlayers(players, true); await UpdatePlayerIndices(); } }
/// <summary> /// Adds the current agent connection to all its available channels /// </summary> /// <param name="connectionId">Agent connection id</param> /// <param name="channels">All agent's channels</param> /// <returns></returns> private async Task AddAgentChannels(string connectionId, List <LivechatChannel> channels) { foreach (var channel in channels) { await groupManager.AddAsync(connectionId, channel.ChannelId); } }
/// <summary> /// Add a user connectionId into channel's group /// </summary> /// <param name="connectionId">Current user connection id</param> /// <param name="userCurrentChannelId"></param> /// <returns></returns> private async Task NotifyAndAddUserToGroup( string connectionId, string userCurrentChannelId ) { await groupManager.AddAsync( connectionId, userCurrentChannelId ); // Sends the channel to livechat customer await currentUser.SendAsync( HubMessages.NEW_CHANNEL_REGISTERED, userCurrentChannelId ); }
public async Task <IActionResult> Create() { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } GroupViewModel groupViewModel = GetGroupViewModelFromRequest(); GroupDto groupDto = _dataAdapter.Map <GroupDto>(groupViewModel); await _groupManager.AddAsync(groupDto); await SaveFileFromRequestAsync(groupDto.Id); return(CreatedAtAction("Get", new { id = groupDto.Id }, _dataAdapter.Map <GroupViewModel>(groupDto))); //return Ok("Saved successful"); }
public async Task AddAsync_WasExecute() { //arrange Group group = new Group { Id = 1 }; _repoMock.Setup(r => r.CreateAsync <Group>(null)); _dataAdapter.Setup(d => d.Map <Group>(null)).Returns(group); _groupManager = new GroupManager(_repoMock.Object, _dataAdapter.Object); //act await _groupManager.AddAsync(null); //assert _repoMock.Verify(mock => mock.CreateAsync(group), Times.Once()); }
public async Task <ActionResult> Add(GroupViewModel groupViewModel) { try { if (ModelState.IsValid) { await groupManager.AddAsync(groupViewModel.ToEntity()); return(RedirectToAction("Index")); } return(View(groupViewModel)); } catch (BusinessException ex) { ModelState.AddModelError(string.Empty, ex.Message); return(View(groupViewModel)); } }