Exemple #1
0
        public async Task <ActionResult <Sport> > Get(int id)
        {
            var sport = await repository.FindSportAsync(id);

            if (sport != null)
            {
                return(sport);
            }

            return(NotFound());
        }
Exemple #2
0
        public async Task <ActionResult <dynamic> > GenerateTeams(
            int peladaId, int sportId, List <Athlete> athletes)
        {
            int numberAthletes = athletes.Count;
            var sport          = await sportRepository.FindSportAsync(sportId);

            if (sport == null ||
                !this.checkNumberOfAthletes(numberAthletes, sport.NumberPlayers))
            {
                return(BadRequest(new { message = "Parametros inválidos" }));
            }

            string[] arrayOfQuantity =
                teamRepository.getArrayQuantityTeams(sport.NumberPlayersTeam, numberAthletes);

            teamRepository.CheckReserveBank(arrayOfQuantity);

            int quantityOfTeams = Convert.ToInt32(arrayOfQuantity[0]);

            try
            {
                List <TeamAthletesView> teamAthletes = await this.CreateTeamAndAthletes(
                    athletes,
                    quantityOfTeams,
                    numberAthletes,
                    sport.NumberPlayersTeam,
                    peladaId
                    );

                return(StatusCode(200, new
                {
                    teamAthletes = teamAthletes,
                    reserveBank = this.GetReserveBank()
                }));
            }
            catch (Exception e)
            {
                return(BadRequest(new
                {
                    error =
                        String.Format(
                            "Não foi possível efetuar a operação devido -> {0}", e.Message)
                }));
            }
        }