Ejemplo n.º 1
0
        public async Task <StatusCodeResult> RemovePlayer([FromRoute] int teamId, [FromBody] PlayerOperationRequest request, CancellationToken cancellationToken)
        {
            var team = await _teamsRepository.GetByIdWithFormationAsync(teamId);

            var player = await _playersRepository.GetByIdAsync(request.PlayerId);

            team.Formation.RemovePlayer(player);
            await _teamsRepository.UpdateAsync(team);

            return(Ok());
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <AddPlayerToRoosterResponse> > AddPlayerToRooster([FromRoute] int teamId, [FromBody] PlayerOperationRequest request, CancellationToken cancellationToken)
        {
            var team = await _teamsRepository.GetByIdWithRoosterAsync(teamId);

            var player = await _playersRepository.GetByIdAsync(request.PlayerId);

            team.AddPlayer(player);

            await _teamsRepository.UpdateAsync(team);

            var response = new AddPlayerToRoosterResponse();

            {
                response.TeamId   = teamId;
                response.PlayerId = request.PlayerId;
            }
            return(Ok(response));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult <AddPlayerToFormationResponse> > AddPlayerToFormation([FromRoute] int teamId, [FromBody] PlayerOperationRequest request, CancellationToken cancellationToken)
        {
            var team = await _teamsRepository.GetByIdWithFormationAsync(teamId);

            var player = await _playersRepository.GetByIdAsync(request.PlayerId);

            team.Formation.AddPlayer(player);

            await _teamsRepository.UpdateAsync(team);

            var response = new AddPlayerToFormationResponse();

            {
                response.TeamId     = teamId;
                response.PlayerId   = request.PlayerId;
                response.PositionNo = team.Formation.Postitions.Single(x => x.Player?.Id == request.PlayerId).PositionNo;
            }
            return(Ok(response));
        }