/// <summary>
        /// Add a new team
        /// </summary>
        /// <param name="tournamentId"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        public ActionResult <Team> AddTeam(int tournamentId, string name)
        {
            DbModels.Tournament tournament = this._repoWrapper.Tournament.GetById(tournamentId);
            if (tournament == null)
            {
                return(new NotFoundResult());
            }

            // Only update while tournament not started
            if (tournament.State != DbModels.TournamentState.Created)
            {
                return(new BadRequestObjectResult("Tournament allready started of finished"));
            }

            DbModels.Team team = new DbModels.Team
            {
                Name = name
            };

            this._repoWrapper.Team.Create(team);
            this._repoWrapper.Team.SaveChanges();

            tournament.Teams.Add(team);
            this._repoWrapper.Tournament.SaveChanges();

            return(new ActionResult <Team>(new Team(team)));
        }
        /// <summary>
        /// Remove a team
        /// </summary>
        /// <param name="tournamentId"></param>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public ActionResult RemoveTeam(int tournamentId, int teamId)
        {
            DbModels.Tournament tournament = this._repoWrapper.Tournament.GetById(tournamentId);
            if (tournament == null)
            {
                return(new NotFoundResult());
            }

            // Only update while tournament not started
            if (tournament.State != DbModels.TournamentState.Created)
            {
                return(new BadRequestObjectResult("Tournament allready started of finished"));
            }

            DbModels.Team dbTeam = this._repoWrapper.Team.GetById(teamId);
            if (dbTeam == null)
            {
                return(new NotFoundResult());
            }

            this._repoWrapper.Team.Delete(dbTeam);
            this._repoWrapper.Team.SaveChanges();

            return(new OkResult());
        }
        /// <summary>
        /// Get a team
        /// </summary>
        /// <param name="tournamentId"></param>
        /// <param name="teamId"></param>
        /// <returns></returns>
        public ActionResult <Team> GetTeam(int tournamentId, int teamId)
        {
            DbModels.Tournament tournament = this._repoWrapper.Tournament.GetById(tournamentId);
            if (tournament == null)
            {
                return(new NotFoundResult());
            }

            DbModels.Team dbTeam = this._repoWrapper.Team.GetById(teamId);
            if (dbTeam == null)
            {
                return(new NotFoundResult());
            }

            return(new ActionResult <Team>(new Team(dbTeam)));
        }
Exemple #4
0
 internal Team(db.Team team)
 {
     Id   = team.Id;
     Name = team.Name;
 }