public void Create(Tournament tournament)
        {
            if (tournament.MapTemplates == null || tournament.MapTemplates.Count() == 0)
            {
                throw new Exceptions.ApplicationException("No map templates", ErrorCode.MapTemplatesRequired);
            }

            var gameOptions = Mapper.Map<Domain.Games.GameOptions>(tournament.Options);

            var newTournament = new Domain.Tournaments.Tournament(
                tournament.Name, tournament.NumberOfTeams, tournament.NumberOfGroupGames, tournament.NumberOfKnockoutGames,
                tournament.NumberOfFinalGames, tournament.StartOfRegistration, tournament.StartOfTournament, gameOptions);

            foreach (var mapTemplateName in tournament.MapTemplates)
            {
                // Ensure MapTemplates exist
                if (this.UnitOfWork.MapTemplateDescriptors.Get(mapTemplateName) == null)
                {
                    throw new Exceptions.ApplicationException("Cannot find map template", ErrorCode.CannotFindMapTemplate);
                }
            }

            newTournament.MapTemplates.Clear();
            newTournament.MapTemplates.AddRange(tournament.MapTemplates);

            if (this.UnitOfWork.Tournaments.ExistsWithName(tournament.Name))
            {
                throw new Exceptions.ApplicationException("Name is already taken", ErrorCode.CannotCreateTournament);
            }

            this.UnitOfWork.Tournaments.Add(newTournament);
            this.UnitOfWork.Commit();
        }
Exemplo n.º 2
0
        public Tournament Get(Guid tournamentId)
        {
            Require.NotEmpty(tournamentId, nameof(tournamentId));

            Domain.Tournaments.Tournament tournament = GetTournament(tournamentId);

            return(Mapper.Map <Tournament>(tournament));
        }
Exemplo n.º 3
0
        private Domain.Tournaments.TournamentTeam GetTeam(Domain.Tournaments.Tournament tournament, Guid teamId)
        {
            var team = tournament.Teams.FirstOrDefault(x => x.Id == teamId);

            if (team == null)
            {
                throw new Exceptions.ApplicationException("Cannot find team", ErrorCode.TournamentTeamNotFound);
            }

            return(team);
        }
Exemplo n.º 4
0
        public async Task <Guid> Create(Tournament tournament)
        {
            this.CheckAdmin();

            if (tournament.MapTemplates == null || tournament.MapTemplates.Count() == 0)
            {
                throw new Exceptions.ApplicationException("No map templates", ErrorCode.MapTemplatesRequired);
            }

            var gameOptions = Mapper.Map <Domain.Games.GameOptions>(tournament.Options);

            var newTournament = new Domain.Tournaments.Tournament(
                tournament.Name, tournament.NumberOfTeams, tournament.NumberOfGroupGames, tournament.NumberOfKnockoutGames,
                tournament.NumberOfFinalGames, tournament.StartOfRegistration, tournament.StartOfTournament, gameOptions);

            foreach (var mapTemplateName in tournament.MapTemplates)
            {
                // Ensure MapTemplates exist
                if (this.UnitOfWork.MapTemplateDescriptors.Get(mapTemplateName) == null)
                {
                    throw new Exceptions.ApplicationException("Cannot find map template", ErrorCode.CannotFindMapTemplate);
                }
            }

            newTournament.MapTemplates.Clear();
            newTournament.MapTemplates.AddRange(tournament.MapTemplates);

            if (this.UnitOfWork.Tournaments.ExistsWithName(tournament.Name))
            {
                throw new Exceptions.ApplicationException("Name is already taken", ErrorCode.CannotCreateTournament);
            }

            this.UnitOfWork.Tournaments.Add(newTournament);
            this.UnitOfWork.Commit();

            return(newTournament.Id);
        }