Exemplo n.º 1
0
        public async Task <IHttpActionResult> SignUp([FromBody] PlayerToMatchModel transaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            Match match = await _matchesRepo.GetMatchByIdAsync(transaction.MatchId);

            if (match == null)
            {
                return(NotFound());
            }
            else
            {
                var playerEntity = await _playersRepo.GetUserByUsername(transaction.UserName);

                if (playerEntity == null)
                {
                    return(NotFound());
                }

                var playerDto = new UserSubscription(playerEntity, DateTime.Now);

                if (match.Players.Any(p => p.User == playerDto.User))
                {
                    return(BadRequest("Player is already in the match"));
                }
                else
                {
                    if (await _matchesRepo.SignUpPlayerAsync(match, playerDto) <= 0)
                    {
                        return(InternalServerError());
                    }
                    return(StatusCode(HttpStatusCode.NoContent));
                }
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> Dismiss([FromBody] PlayerToMatchModel transaction)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }


            var match = await _matchesRepo.GetMatchByIdAsync(transaction.MatchId);

            if (match == null)
            {
                return(NotFound());
            }
            else
            {
                var playerEntity = await _playersRepo.GetUserByUsername(transaction.UserName);

                if (playerEntity == null)
                {
                    return(NotFound());
                }

                var subscription = match.Players.SingleOrDefault(p => p.User == playerEntity.UserName);
                if (subscription != null)
                {
                    if (await _matchesRepo.DismissPlayerAsync(match, subscription) <= 0)
                    {
                        return(InternalServerError());
                    }
                    return(StatusCode(HttpStatusCode.NoContent));
                }
                else
                {
                    return(BadRequest("Player was not signed up for the match"));
                }
            }
        }