/// <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", dbType: DbType.Int32, direction: ParameterDirection.Output); connection.Execute("dbo.spPrizes_Insert", p, commandType: CommandType.StoredProcedure); model.Id = p.Get <int>("@id"); return(model); } }
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); }
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); }
public PersonModel 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", dbType: DbType.Int32, direction: ParameterDirection.Output); connection.Execute("dbo.spPeople_Insert", p, commandType: CommandType.StoredProcedure); model.Id = p.Get <int>("@id"); return(model); } }
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); } } }
public void CompleteTournament(TournamentModel model) { //spTournaments_Complete using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db))) { var p = new DynamicParameters(); p.Add("@id", model.Id); connection.Execute("spTournaments_Complete", p, commandType: CommandType.StoredProcedure); } }
public void UpdateMatchup(MatchupModel model) { //spMatchups_Update @id, @Winner 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.spMatchups_Update", p, commandType: CommandType.StoredProcedure); } //spMatchupEntries_Update id, TeamCompeting Id, 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("spMatchupEntries_Update", p, commandType: CommandType.StoredProcedure); } } } }
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) //bl { //The prizes for each tournament by each id //Populate prizes p = new DynamicParameters(); p.Add("@TournamentId", t.Id); // t.Prizes = connection.Query <PrizeModel>("dbo.spPrizes_GetByTournament", p, commandType: CommandType.StoredProcedure).ToList(); //Populate the 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 the Rounds //Only matchups that are for our tournament 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 the Rounds //Only matchups that are for our tournament m.Entries = connection.Query <MatchupEntryModel>("dbo.spMatchupEntries_GetByMatchup", p, commandType: CommandType.StoredProcedure).ToList(); //Populate each entry (2 models) //Populate ach 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); }
public void CreateTournament(TournamentModel model) { using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db))) { SaveTournament(connection, model); SaveTournamentPrizes(connection, model); SaveTournamentEnteries(connection, model); // return model; SaveTournamentRounds(connection, model); TournamentLogic.UpdateTournamentResults(model); } }