public async Task <List <ViewGetScoreDto> > Handle(GetScoresQuery request, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            List <ViewGetScoreDto> list = new List <ViewGetScoreDto>();

            int p1Score = gameSetup.State.Player2.Board.ShipList.Where(s => s.IsSunk).Count();
            int p2Score = gameSetup.State.Player1.Board.ShipList.Where(s => s.IsSunk).Count();

            list.Add(new ViewGetScoreDto {
                PlayerName = gameSetup.State.Player1.Name, Score = p1Score
            });
            list.Add(new ViewGetScoreDto {
                PlayerName = gameSetup.State.Player2.Name, Score = p2Score
            });

            return(list);
        }
Ejemplo n.º 2
0
        public async Task <ActionResult <GetScoresResponse> > GetScores([FromRoute] GetScoresRequest request)
        {
            if (request.Score < 0 || request.Score > 5)
            {
                return(BadRequest("Score is out of range"));
            }

            var query = new GetScoresQuery
            {
                Score = request.Score
            };

            var result = await _mediator.Send(query);

            if (!result.Success)
            {
                return(StatusCode(500, "Unable to get score data at this time"));
            }

            var response = _mapper.Map <GetScoresResponse>(result);

            return(response);
        }