Esempio n. 1
0
        public List <Tournament> GetTournament_All()
        {
            List <Tournament> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                output = connection.Query <Tournament>("dbo.spTournaments_GetAll").ToList();
                foreach (Tournament t in output)
                {
                    var p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    t.Prizes       = connection.Query <Prize>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
                    t.EnteredTeams = connection.Query <Team>("dbo.spTeams_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();
                    foreach (Team tm in t.EnteredTeams)
                    {
                        p = new DynamicParameters();
                        p.Add("@TeamId", tm.Id);
                        tm.TeamMembers = connection.Query <Person>("dbo.spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
                    }
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);
                    List <Matchup> matchups = connection.Query <Matchup>("dbo.spMatchups_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    foreach (Matchup m in matchups)
                    {
                        p = new DynamicParameters();
                        p.Add("@MatchupId", m.Id);
                        m.Entries = connection.Query <MatchupEntry>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList();

                        List <Team> allTeams = GetTeam_All();

                        if (m.WinnerId > 0)
                        {
                            m.Winner = allTeams.Find(tm => tm.Id == m.WinnerId);
                        }

                        foreach (MatchupEntry e in m.Entries)
                        {
                            if (e.TeamCompetingId > 0)
                            {
                                e.TeamCompeting = allTeams.Find(tm => tm.Id == e.TeamCompetingId);
                            }
                            if (e.ParentMatchupId > 0)
                            {
                                e.ParentMatchup = matchups.Find(ma => ma.Id == e.ParentMatchupId);
                            }
                        }
                    }

                    List <Matchup> currentRound = new List <Matchup>();
                    int            roundIndex   = 1;

                    foreach (Matchup m in matchups)
                    {
                        if (m.MatchupRound > roundIndex)
                        {
                            t.Rounds.Add(currentRound);
                            currentRound = new List <Matchup>();
                            roundIndex++;
                        }
                        currentRound.Add(m);
                    }
                    t.Rounds.Add(currentRound);
                }
            }
            return(output);
        }
        //TODO- Make the CreatePrize method actually save to the database
        /// <summary>
        /// Saves a new prize to the database
        /// </summary>
        /// <param name="model">The prize information</param>
        /// <returns>The prize information, including the unique identifier</returns>
        public PrizeModel CreatePrize(PrizeModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@PlaceNumber", model.PlaceNumber);
                p.Add("@PlaceName", model.PlaceName);
                p.Add("@PrizeAmount", model.PrizeAmount);
                p.Add("@PrizePercentage", model.PrizePercentage);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);  //The id will output to the user

                connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id"); //FInd the id parameter


                return(model);
            } //At the end of this curly brace the sql connection will be destroyed properly. Prevent memory leaks
        }
Esempio n. 3
0
        //TODO - Make the CreatePrize method actually save to the databse.
        /// <summary>
        /// Saves a new prize to the database
        /// </summary>
        /// <param name="model">The prize information</param>
        /// <returns>The prize information, including the unique identifier.</returns>
        public void CreatePrize(PrizeModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@PlaceNumber", model.PlaceNumber);
                p.Add("@PlaceName", model.PlaceName);
                p.Add("@PrizeAmount", model.PrizeAmount);
                p.Add("@PrizePercentage", model.PrizePercentage);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");
            }
        }
Esempio n. 4
0
        public void CompleteTournament(TournamentModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@id", model.Id);

                connection.Execute("dbo.spTournaments_Complete", p, commandType: CommandType.StoredProcedure);
            }
        }
        public List <PersonModel> GetPerson_All()
        {
            List <PersonModel> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                output = connection.Query <PersonModel>("dbo.spPeople_GetAll").ToList();
            }

            return(output);
        }
Esempio n. 6
0
        public void CreateTournament(TournamentModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                SaveTournament(connection, model);

                SaveTournamentPrizes(connection, model);

                SaveTournamentEntries(connection, model);

                SaveTournamentRounds(connection, model);

                TournamentLogic.UpdateTournamentResults(model);
            }
        }
Esempio n. 7
0
        /// <summary>
        /// Saves a new prize to the database
        /// </summary>
        /// <param name="model">the prize information</param>
        /// <returns>The prize information, including the unique identifier</returns>
        public PrizeModel CreatePrize(PrizeModel model)
        {
            //IDbConnection interface is extensible to text file connection, mysql, etc.
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@placeNumber", model.PlaceNumber);
                p.Add("@placeName", model.PlaceName);
                p.Add("@prizeAmount", model.PrizeAmount);
                p.Add("@prizePercentage", model.PrizePercentage);
                //Using dapper library, this is the way to output a value from the sql db
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");

                return(model);
            }
        }
Esempio n. 8
0
        public List <TournamentModel> GetTournament_All()
        {
            List <TournamentModel> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                output = connection.Query <TournamentModel>("dbo.spTournaments_GetAll").ToList();
                var p = new DynamicParameters();

                foreach (TournamentModel t in output)
                {
                    // Populate Prizes
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    t.Prizes = connection.Query <PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    // Populate Teams
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    t.EnteredTeams = connection.Query <TeamModel>("dbo.spTeam_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    foreach (TeamModel team in t.EnteredTeams)
                    {
                        p = new DynamicParameters();
                        p.Add("@TeamId", team.Id);

                        team.TeamMembers = connection.Query <PersonModel>("dbo.spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
                    }

                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    // Populate Rounds
                    List <MatchupModel> matchups = connection.Query <MatchupModel>("dbo.spMatchups_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    foreach (MatchupModel m in matchups)
                    {
                        p = new DynamicParameters();
                        p.Add("@MatchupId", m.Id);

                        // Populate Rounds
                        m.Entries = connection.Query <MatchupEntryModel>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList();

                        // Populate each matchup (1 model)
                        List <TeamModel> allTeams = GetTeam_All();

                        if (m.WinnerId > 0)
                        {
                            m.Winner = allTeams.Where(x => x.Id == m.WinnerId).First();
                        }

                        foreach (var me in m.Entries)
                        {
                            if (me.TeamCompetingId > 0)
                            {
                                me.TeamCompeting = allTeams.Where(x => x.Id == me.TeamCompetingId).First();
                            }
                            if (me.ParentMatchupId > 0)
                            {
                                me.ParentMatchup = matchups.Where(x => x.Id == me.ParentMatchupId).First();
                            }
                        }
                    }

                    // List<List<MatchupModel>>
                    List <MatchupModel> currRow = new List <MatchupModel>();
                    int currRound = 1;

                    foreach (MatchupModel m in matchups)
                    {
                        if (m.MatchupRound > currRound)
                        {
                            t.Rounds.Add(currRow);
                            currRow    = new List <MatchupModel>();
                            currRound += 1;
                        }

                        currRow.Add(m);
                    }

                    t.Rounds.Add(currRow);
                }
            }

            return(output);
        }
Esempio n. 9
0
        public TeamModel CreateTeam(TeamModel T)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", T.TeamName);
                p.Add("@TeamId", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("[dbo].[spInsert_Teams]", p, commandType: CommandType.StoredProcedure);

                T.TeamModelID = p.Get <int>("@TeamId");

                foreach (var t in T.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", T.TeamModelID);
                    p.Add("@PeopleID", t.PeopleID);

                    connection.Execute("dbo.spInsert_TeamMembers", p, commandType: CommandType.StoredProcedure);
                }

                return(T);
            }
        }
Esempio n. 10
0
 public void CreateTournament(TournamentModel model)
 {
     using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
     {
         SaveTournament(model, connection);
         SaveTournamentPrizes(model, connection);
         SaveTournamentTeams(model, connection);
     }
 }
Esempio n. 11
0
        public List <TournamentModel> GetTournament_All()
        {
            List <TournamentModel> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                output = connection.Query <TournamentModel>("dbo.spTournaments_GetAll").ToList();
                var p = new DynamicParameters();

                foreach (TournamentModel t in output)
                {
                    // Populate Prizes
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    t.Prizes = connection.Query <PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    // Populate Teams
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    t.EnteredTeams = connection.Query <TeamModel>("dbo.spTeam_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    foreach (TeamModel team in t.EnteredTeams)
                    {
                        p = new DynamicParameters();
                        p.Add("@TeamId", team.Id);

                        team.TeamMembers = connection.Query <PersonModel>("spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
                    }

                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    List <MatchupModel> matchups = connection.Query <MatchupModel>("dbo.spMatchups_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    //Populate Matchups
                    foreach (MatchupModel m in matchups)
                    {
                        p = new DynamicParameters();
                        p.Add("@MatchupId", m.Id);

                        m.Entries = connection.Query <MatchupEntryModel>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList();

                        List <TeamModel> allTeams = GetTeam_All();
                        if (m.WinnerId > 0)
                        {
                            m.Winner = allTeams.Where(x => x.Id == m.WinnerId).First();
                        }

                        foreach (MatchupEntryModel me in m.Entries)
                        {
                            if (me.TeamCompetingId > 0)
                            {
                                me.TeamCompeting = allTeams.Where(x => x.Id == me.TeamCompetingId).First();
                            }

                            if (me.ParentMatchupId > 0)
                            {
                                // The stored procedure orders the matchups by matchupId so in the
                                // previous matchups (parents) should already be in matchups. (matachups.entries.parentmatchup)
                                me.ParentMatchup = matchups.Where(x => x.Id == me.ParentMatchupId).First();
                            }
                        }
                    }

                    // // Populate Rounds: List<List<MatchupModel>>
                    List <MatchupModel> currRow = new List <MatchupModel>();
                    int currRound = 1;

                    foreach (MatchupModel m in matchups)
                    {
                        if (m.MatchupRound > currRound)
                        { // We have moved to the next round, so we log the previous round and clean up for the new one
                            t.Rounds.Add(currRow);
                            currRow = new List <MatchupModel>();
                            currRound++;
                        }

                        currRow.Add(m);
                    }

                    t.Rounds.Add(currRow);
                }
            }

            return(output);

            //TournamentModel
            //    - Id
            //    - TournamentName
            //    - EntryFee
            //    - EnteredTeams
            //        - Id
            //        - TeamName
            //        - TeamMembers
            //    - Prizes
            //    - Rounds
            //        - Matchups
            //            - Entries
            //                - Id
            //                - TeamCompetingId
            //                - TeamCompeting
            //                - Score
            //                - ParentMatchupId
            //                - ParentMatchup
        }
Esempio n. 12
0
        public List <TournamentModel> GetTournament_All()
        {
            List <TournamentModel> tournaments;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                tournaments = connection.Query <TournamentModel>("dbo.spTournaments_GetAll").ToList();


                foreach (TournamentModel tournament in tournaments)
                {
                    var p = new DynamicParameters();
                    p.Add("@TournamentId", tournament.Id);

                    tournament.Prizes = connection.Query <PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    tournament.EnteredTeams = connection.Query <TeamModel>("dbo.spTeams_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    foreach (TeamModel team in tournament.EnteredTeams)
                    {
                        var m = new DynamicParameters();
                        m.Add("@TeamId", team.Id);

                        team.TeamMembers = connection.Query <PersonModel>("dbo.spTeamMembers_GetByTeam", m, commandType: CommandType.StoredProcedure).ToList();
                    }

                    List <MatchupModel> matchups = connection.Query <MatchupModel>("dbo.spMatchups_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    foreach (MatchupModel matchup in matchups)
                    {
                        p = new DynamicParameters();
                        p.Add("@MatchupId", matchup.Id);

                        matchup.Entries = connection.Query <MatchupEntryModel>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList();

                        //if there is a winner grabs the winner from the tournaments entered teams based on winner id.
                        if (matchup.WinnerId > 0)
                        {
                            matchup.Winner = tournament.EnteredTeams.Where(x => x.Id == matchup.WinnerId).First();
                        }

                        //Grabs the models for team competing and parent matchup based off the passed in ids for both from the sql database
                        foreach (MatchupEntryModel entry in matchup.Entries)
                        {
                            if (entry.TeamCompetingId > 0)
                            {
                                entry.TeamCompeting = tournament.EnteredTeams.Where(x => x.Id == entry.TeamCompetingId).First();
                            }

                            if (entry.ParentMatchupId > 0)
                            {
                                entry.ParentMatchup = matchups.Where(x => x.Id == entry.ParentMatchupId).First();
                            }
                        }
                    }
                    //this part will populate our rounds with lists of matchups based off round number
                    int totalRounds  = matchups.OrderByDescending(x => x.MatchupRound).First().MatchupRound;
                    int currentRound = 1;
                    while (totalRounds >= currentRound)
                    {
                        List <MatchupModel> round = new List <MatchupModel>();
                        foreach (MatchupModel match in matchups)
                        {
                            if (match.MatchupRound == currentRound)
                            {
                                round.Add(match);
                            }
                        }
                        tournament.Rounds.Add(round);
                        currentRound++;
                    }
                }
            }

            return(tournaments);
        }
        public List <TournamentModel> GetTournament_All()
        {
            List <TournamentModel> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                output = connection.Query <TournamentModel>("dbo.spTournaments_GetAll").ToList();

                foreach (TournamentModel tournament in output)
                {
                    // Populate Prizes
                    DynamicParameters param = new DynamicParameters();
                    param.Add("@TournamentId", tournament.Id);
                    tournament.Prizes = connection.Query <PrizeModel>("dbo.spPrizes_GetByTournament", param, commandType: CommandType.StoredProcedure).ToList();

                    // Populate Teams
                    tournament.EnteredTeams = connection.Query <TeamModel>("dbo.spTeams_GetByTournament", param, commandType: CommandType.StoredProcedure).ToList();

                    foreach (TeamModel team in tournament.EnteredTeams)
                    {
                        param = new DynamicParameters();
                        param.Add("TeamId", team.Id);
                        team.TeamMembers = connection
                                           .Query <PersonModel>("dbo.spTeamMembers_GetByTeam", param, commandType: CommandType.StoredProcedure)
                                           .ToList();
                    }

                    // Populate Rounds
                    param = new DynamicParameters();
                    param.Add("@TournamentId", tournament.Id);
                    List <MatchupModel> matchups = connection.Query <MatchupModel>("spMatchups_GetByTournament", param, commandType: CommandType.StoredProcedure)
                                                   .ToList();

                    foreach (MatchupModel matchup in matchups)
                    {
                        // Populate Entries
                        param = new DynamicParameters();
                        param.Add("@MatchupId", matchup.Id);
                        matchup.Entries = connection.Query <MatchupEntryModel>("spMatchupEntries_GetByMatchup", param, commandType: CommandType.StoredProcedure)
                                          .ToList();

                        List <TeamModel> allTeams = GetTeam_All();

                        // Populate Winner in MatchupModel with winnerId we got from db
                        if (matchup.WinnerId > 0)
                        {
                            matchup.Winner = allTeams.Where(x => x.Id == matchup.WinnerId).First();
                        }

                        // Populate TeamCompeting and ParentMatchup in MatchupEntryModel with coresponding IDs we got from db
                        foreach (MatchupEntryModel entry in matchup.Entries)
                        {
                            if (entry.TeamCompetingId > 0)
                            {
                                entry.TeamCompeting = allTeams.Where(x => x.Id == entry.TeamCompetingId).First();
                            }
                            if (entry.ParentMatchupId > 0)
                            {
                                entry.ParentMatchup = matchups.Where(x => x.Id == entry.ParentMatchupId).First();
                            }
                        }
                    }

                    // List<List<MatchupModel>>
                    List <MatchupModel> currRow = new List <MatchupModel>();
                    int currRound = 1;
                    foreach (MatchupModel matchup in matchups)
                    {
                        if (matchup.MatchupRound > currRound)
                        {
                            tournament.Rounds.Add(currRow);
                            currRow    = new List <MatchupModel>();
                            currRound += 1;
                        }

                        currRow.Add(matchup);
                    }
                    tournament.Rounds.Add(currRow);
                }
            }

            return(output);
        }
Esempio n. 14
0
        public TeamModel CreateTeam(TeamModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);  //The id will output to the user

                connection.Execute("dbo.spTeams._Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id"); //Find the id parameter

                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.id);

                    connection.Execute("dbo.spTeamMembers._Insert", p, commandType: CommandType.StoredProcedure);
                }

                return(model);
            } //At the end of this curly brace the sql connection will be destroyed properly. Prevent memory leaks
        }
Esempio n. 15
0
        //This is the method/process to get data from a DB and send it into a list
        public List <PersonModel> GetPerson_All()
        {
            List <PersonModel> getPersons;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                getPersons = connection.Query <PersonModel>("dbo.spGetPeople").ToList();
            }
            return(getPersons);
        }
Esempio n. 16
0
 public void TournamentModel CreateTournament(TournamentModel model)
 {
     using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
     {
         SaveTournament(connection, model);
         SaveTournamentPrizes(connection, model);
         SaveTournamentEntries(connection, model);
     }
 }
Esempio n. 17
0
        public List <TeamModel> GetTeam_All()
        {
            List <TeamModel> getTeams;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                getTeams = connection.Query <TeamModel>("dbo.spGet_Team").ToList();

                foreach (TeamModel t in getTeams)
                {
                    var p = new DynamicParameters();
                    p.Add("@TeamId", t.TeamModelID);
                    t.TeamMembers = connection.Query <PersonModel>("dbo.spGetByTeam_TeamMembers", p, commandType: CommandType.StoredProcedure).ToList();
                }
            }

            return(getTeams);
        }
Esempio n. 18
0
        public TeamModel CreateTeam(TeamModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); //comes out not comes in like the previous

                connection.Execute("dbo.spTeams_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");

                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }

                return(model);
            }
        }
Esempio n. 19
0
        public List <TournamentModel> GetTournament_All()
        {
            List <TournamentModel> getTournaments;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                getTournaments = connection.Query <TournamentModel>("dbo.spGet_Tournaments").ToList();
                foreach (var tour in getTournaments)
                {
                    var p = new DynamicParameters();
                    p.Add("@TournamentId", tour.Id);
                    //TODO - add the rest of these fields
                    //tour.TeamMembers = connection.Query<PersonModel>("dbo.spGetByTeam_TeamMembers", p, commandType: CommandType.StoredProcedure).ToList();
                }
            }
            return(getTournaments);
        }
Esempio n. 20
0
        public List <TeamModel> GetTeam_All()
        {
            List <TeamModel> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                output = connection.Query <TeamModel>("dbo.spTeam_GetAll").ToList();
                foreach (TeamModel team in output)
                {
                    var p = new DynamicParameters();
                    p.Add("@TeamId", team.Id);
                    team.TeamMembers = connection.Query <PersonModel>("dbo.spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
                }
            }

            return(output);
        }
Esempio n. 21
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"> the prize information</param>
        /// <returns>returns the prize information including id from db</returns>
        ///

        public PrizeModel CreatePrize(PrizeModel model)
        {
            //Connect to our sql instance
            //using dapper as a ORM.
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments")))
            {
                // Initialise a variable
                var p = new DynamicParameters();
                p.Add("@PlaceNumber", model.PlaceNumber);
                p.Add("@PlaceName", model.PlaceName);
                p.Add("@PrizeAmount", model.PrizeAmount);
                p.Add("@PrizePercentage", model.PrizePercentage);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id"); //gets dynamic paramter of type int, and gets it back
                return(model);
            }
            //TODO What happens if the database connection is not there, or what happens if the
        }
Esempio n. 22
0
        public List <TournamentModel> GetTournament_All()
        {
            List <TournamentModel> output = new List <TournamentModel>();

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();

                output = connection.Query <TournamentModel>("dbo.spTournaments_GetAll").ToList();

                foreach (TournamentModel t in output)
                {
                    //populate prizes
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    t.Prizes = connection.Query <PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();



                    //populate Teams
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    t.EnteredTeams = connection.Query <TeamModel>("dbo.spTeam_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    // przeszukaj liste obiektow w liscie output i do kazdego obiekut
                    //przypisz osoby Person model (id) = Team model (personid) dla konkretnego teamu
                    //TeamMembers(TeamId)

                    foreach (TeamModel team in t.EnteredTeams)
                    {
                        p = new DynamicParameters();
                        p.Add("@TeamId", team.Id);

                        team.TeamMembers = connection.Query <PersonModel>("dbo.spTeamMembers_GetByTeam", p, commandType: CommandType.StoredProcedure).ToList();
                    }

                    //populate rounds
                    p = new DynamicParameters();
                    p.Add("@TournamentId", t.Id);

                    List <MatchupModel> matchups = connection.Query <MatchupModel>("dbo.spMatchup_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList();

                    foreach (MatchupModel m in matchups)
                    {
                        p = new DynamicParameters();
                        p.Add("@MatchupId", m.Id);

                        m.Entries = connection.Query <MatchupEntryModel>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList();

                        //Populate each entry (2models)
                        //populate each matchup(1model)

                        List <TeamModel> allTeams = GetTeam_All();

                        if (m.WinnerId > 0)
                        {
                            m.Winner = allTeams.Where(x => x.Id == m.WinnerId).First();
                        }
                        foreach (var me in m.Entries)
                        {
                            if (me.TeamCompetingId > 0)
                            {
                                me.TeamCompeting = allTeams.Where(x => x.Id == me.TeamCompetingId).First();
                            }

                            if (me.ParentMatchupId > 0)
                            {
                                me.ParentMatchup = matchups.Where(x => x.Id == me.ParentMatchupId).First();
                            }
                        }
                    }
                    List <MatchupModel> currRow = new List <MatchupModel>();
                    int currRound = 1;
                    // List<List<MatchupModel>>
                    foreach (MatchupModel m in matchups)
                    {
                        if (m.MatchupRound > currRound)
                        {
                            t.Rounds.Add(currRow);
                            currRow    = new List <MatchupModel>();
                            currRound += 1;
                        }
                        currRow.Add(m);
                    }
                    t.Rounds.Add(currRow);
                }
            }

            return(output);
        }
Esempio n. 23
0
        public void CreateTeam(TeamModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
                p.Add("@TeamName", model.TeamName);

                connection.Execute("dbo.spTeams_Insert", p, commandType: CommandType.StoredProcedure);

                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.Id);

                    //TODO - Check the crash happening on create team button pressed.
                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Esempio n. 24
0
        public void UpdateMatchup(MatchupModel model)
        {
            // spMatchup_Update @id, @WinnerId

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                if (model.Winner != null)
                {
                    p.Add("@id", model.Id);
                    p.Add("@WinnerId", model.Winner.Id);


                    connection.Execute("dbo.spMatchup_Update", p, commandType: CommandType.StoredProcedure);
                }

                // spMatchunEntries_Update id, TeamCompetingId Score

                foreach (MatchupEntryModel me in model.Entries)
                {
                    if (me.TeamCompeting != null)
                    {
                        p = new DynamicParameters();
                        p.Add("@id", me.Id);
                        p.Add("@TeamCompetingId", me.TeamCompeting.Id);
                        p.Add("@Score", me.Score);

                        connection.Execute("dbo.spMatchupEntries_Update", p, commandType: CommandType.StoredProcedure);
                    }
                }
            }
        }
Esempio n. 25
0
        public void UpdateMatchup(MatchupModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString("Tournaments")))
            {
                //store matchups and store matchup entries @Id and @WinnerId
                var p = new DynamicParameters();
                p.Add("@Id", model.Id);
                p.Add("@WinnerId", model.Winner.Id);

                connection.Execute("dbo.spMatchups_Update", p, commandType: CommandType.StoredProcedure);

                foreach (MatchupEntryModel me in model.Entries)
                {
                    p = new DynamicParameters();
                    p.Add("@Id", me.Id);
                    p.Add("@TeamCompetingId", me.TeamCompeting.Id);
                    p.Add("@Score", me.Score);

                    connection.Execute("dbo.spMatchupEntries_Update", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Esempio n. 26
0
        public void CreatePerson(PersonModel model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@FirstName", model.FirstName);
                p.Add("@LastName", model.LastName);
                p.Add("@EmailAddress", model.EmailAddress);
                p.Add("@CellphoneNumber", model.CellphoneNumber);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                connection.Execute("dbo.spPeople_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");
            }
        }
        public void CreateTeam(TeamModel model)
        {
            //Тут мы заполняем две таблицы Teams и TeamMembers
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
            {
                var p = new DynamicParameters();
                p.Add("@TeamName", model.TeamName);                                          //Заносим в базу имя команды
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output); //ID - вытаскиваем из базы

                connection.Execute("dbo.spTeam_Insert", p, commandType: CommandType.StoredProcedure);

                model.Id = p.Get <int>("@id");

                foreach (PersonModel tm in model.TeamMembers)
                {
                    p = new DynamicParameters();
                    p.Add("@TeamId", model.Id);
                    p.Add("@PersonId", tm.Id);

                    connection.Execute("dbo.spTeamMembers_Insert", p, commandType: CommandType.StoredProcedure);
                }
            }
        }