Saving a tournament is working

This commit is contained in:
2020-04-09 00:05:25 +02:00
parent a8fefcca3f
commit a3096138f9
3 changed files with 72 additions and 16 deletions

View File

@ -93,16 +93,17 @@ namespace TrackerLibrary.DataAccess
{
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
{
DynamicParameters p = SaveTournament(model, connection);
SaveTournament(model, connection);
p = SaveTournamentPrizes(model, connection, p);
SaveTournamentPrizes(model, connection);
p = SaveTournamentEntries(model, connection, p);
SaveTournamentEntries(model, connection);
SaveTournamentRounds(model, connection);
}
}
private static DynamicParameters SaveTournament(TournamentModel model, IDbConnection connection)
private void SaveTournament(TournamentModel model, IDbConnection connection)
{
var p = new DynamicParameters();
p.Add("@TournamentName", model.TournamentName);
@ -112,14 +113,13 @@ namespace TrackerLibrary.DataAccess
connection.Execute("dbo.spTournaments_Insert", p, commandType: CommandType.StoredProcedure);
model.Id = p.Get<int>("@Id");
return p;
}
private static DynamicParameters SaveTournamentEntries(TournamentModel model, IDbConnection connection, DynamicParameters p)
private static void SaveTournamentEntries(TournamentModel model, IDbConnection connection)
{
foreach (TeamModel tm in model.EnteredTeams)
{
p = new DynamicParameters();
var p = new DynamicParameters();
p.Add("@TournamentId", model.Id);
p.Add("@TeamId", tm.Id);
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
@ -127,15 +127,69 @@ namespace TrackerLibrary.DataAccess
connection.Execute("dbo.spTournamentEntries_Insert", p, commandType: CommandType.StoredProcedure);
}
return p;
}
private static DynamicParameters SaveTournamentPrizes(TournamentModel model, IDbConnection connection, DynamicParameters p)
private static void SaveTournamentRounds(TournamentModel model, IDbConnection connection)
{
// List<List<MatchupModel>> rounds
// List<MatchupEntryModel> Entries
// Loop through the rounds
// Loop through the matchups
// Save the matchup
// Loop through the entries and save them
foreach (List<MatchupModel> round in model.Rounds)
{
foreach (MatchupModel matchup in round)
{
var p = new DynamicParameters();
p.Add("@TournamentId", model.Id);
p.Add("@MatchupRound", matchup.MatchupRound);
p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute("dbo.spMatchups_Insert", p, commandType: CommandType.StoredProcedure);
matchup.Id = p.Get<int>("@id");
foreach (MatchupEntryModel entry in matchup.Entries)
{
p = new DynamicParameters();
p.Add("@MatchupId", matchup.Id);
if(entry.ParentMatchup == null)
{
p.Add("@ParentMatchupId", null);
}
else
{
p.Add("@ParentMatchupId", entry.ParentMatchup.Id);
}
if (entry.TeamCompeting == null)
{
p.Add("@TeamCompetingId", null);
}
else
{
p.Add("@TeamCompetingId", entry.TeamCompeting.Id);
}
p.Add("@id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
connection.Execute("dbo.spMatchupEntries_Insert", p, commandType: CommandType.StoredProcedure);
entry.Id = p.Get<int>("@id");
}
}
}
}
private static void SaveTournamentPrizes(TournamentModel model, IDbConnection connection)
{
foreach (PrizeModel pz in model.Prizes)
{
p = new DynamicParameters();
var p = new DynamicParameters();
p.Add("@TournamentId", model.Id);
p.Add("@PrizeId", pz.Id);
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
@ -143,8 +197,6 @@ namespace TrackerLibrary.DataAccess
connection.Execute("dbo.spTournamentPrizes_Insert", p, commandType: CommandType.StoredProcedure);
}
return p;
}
public List<PersonModel> GetPerson_All()