Ejemplo n.º 1
0
        /// <summary>
        /// Saves the pzize to the SQL database
        /// </summary>
        /// <param name="new_model">The prize information</param>
        /// <returns>The prize information including the unique identifier.</returns>
        public PrizeModel SavePrizeModel(PrizeModel new_model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConnection.ConnectionName(nameOfConnection)))
            {
                var p = new DynamicParameters();
                p.Add("@PlaceNumber", new_model.PlaceNumber);
                p.Add("@PlaceName", new_model.PlaceName);
                p.Add("@PrizeAmount", new_model.PrizeAmount);
                p.Add("@PrizePercentage", new_model.PricePercentage);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

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

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

                return(new_model);
            }
        }
Ejemplo n.º 2
0
        public PersonModel SavePersonModel(PersonModel new_model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConnection.ConnectionName(nameOfConnection)))
            {
                var p = new DynamicParameters();
                p.Add("FirstName", new_model.firstName);
                p.Add("@LastName", new_model.lastName);
                p.Add("@Email", new_model.Email);
                p.Add("@Telephone", new_model.Telephone);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

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

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

                return(new_model);
            }
        }
Ejemplo n.º 3
0
        public TeamModel SaveTeamModel(TeamModel new_model)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConnection.ConnectionName(nameOfConnection)))
            {
                var p = new DynamicParameters();

                p.Add("@TeamName", new_model.TeamName);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

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

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

                foreach (PersonModel person in new_model.TeamMembers)
                {
                    var p2 = new DynamicParameters();

                    p2.Add("@TeamId", new_model.Id);
                    p2.Add("@PersonId", person.Id);

                    connection.Execute("dbo.spTeamMembers_insert_data", p2, commandType: CommandType.StoredProcedure);
                }

                return(new_model);
            }
        }
Ejemplo n.º 4
0
        public void SaveTournamentModel(TournamentModel new_moedl)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConnection.ConnectionName(nameOfConnection)))
            {
                var p = new DynamicParameters();
                p.Add("@TournamentName", new_moedl.TournamentName);
                p.Add("@EntryFee", new_moedl.entryFee);
                p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

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

                new_moedl.ID = p.Get <int>("@id");

                foreach (PrizeModel prize in new_moedl.Prizes)
                {
                    p = new DynamicParameters();

                    p.Add("@TournamentID", new_moedl.ID);
                    p.Add("@PrizeID", prize.Id);
                    p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

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

                foreach (TeamModel team in new_moedl.EnteredTeams)
                {
                    p = new DynamicParameters();

                    p.Add("@TournamentID", new_moedl.ID);
                    p.Add("@TeamID", team.Id);
                    p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);

                    connection.Execute("spTournamentEntries_insert_data", p, commandType: CommandType.StoredProcedure);
                }
            }
        }
Ejemplo n.º 5
0
        public List <TeamModel> GetAllTeams()
        {
            List <TeamModel> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConnection.ConnectionName(nameOfConnection)))
            {
                output = connection.Query <TeamModel>("dbo.spSelectAllTeams").ToList();

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

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

            return(output);
        }
Ejemplo n.º 6
0
        public List <PersonModel> GetAllPeople()
        {
            List <PersonModel> output;

            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConnection.ConnectionName(nameOfConnection)))
            {
                output = connection.Query <PersonModel>("dbo.spSelectAllPeople").ToList();
            }

            return(output);
        }