Saving a tournament is working
This commit is contained in:
@ -93,16 +93,17 @@ namespace TrackerLibrary.DataAccess
|
|||||||
{
|
{
|
||||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
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();
|
var p = new DynamicParameters();
|
||||||
p.Add("@TournamentName", model.TournamentName);
|
p.Add("@TournamentName", model.TournamentName);
|
||||||
@ -112,14 +113,13 @@ namespace TrackerLibrary.DataAccess
|
|||||||
connection.Execute("dbo.spTournaments_Insert", p, commandType: CommandType.StoredProcedure);
|
connection.Execute("dbo.spTournaments_Insert", p, commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
model.Id = p.Get<int>("@Id");
|
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)
|
foreach (TeamModel tm in model.EnteredTeams)
|
||||||
{
|
{
|
||||||
p = new DynamicParameters();
|
var p = new DynamicParameters();
|
||||||
p.Add("@TournamentId", model.Id);
|
p.Add("@TournamentId", model.Id);
|
||||||
p.Add("@TeamId", tm.Id);
|
p.Add("@TeamId", tm.Id);
|
||||||
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
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);
|
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)
|
foreach (PrizeModel pz in model.Prizes)
|
||||||
{
|
{
|
||||||
p = new DynamicParameters();
|
var p = new DynamicParameters();
|
||||||
p.Add("@TournamentId", model.Id);
|
p.Add("@TournamentId", model.Id);
|
||||||
p.Add("@PrizeId", pz.Id);
|
p.Add("@PrizeId", pz.Id);
|
||||||
p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
|
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);
|
connection.Execute("dbo.spTournamentPrizes_Insert", p, commandType: CommandType.StoredProcedure);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<PersonModel> GetPerson_All()
|
public List<PersonModel> GetPerson_All()
|
||||||
|
|||||||
@ -6,6 +6,10 @@ namespace TrackerLibrary.Models
|
|||||||
{
|
{
|
||||||
public class MatchupEntryModel
|
public class MatchupEntryModel
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The unique identifier for the matchupEntry
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents one team in the matchup
|
/// Represents one team in the matchup
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -77,8 +77,8 @@ namespace TrackerLibrary
|
|||||||
{
|
{
|
||||||
//Math.Pow(2, rounds);
|
//Math.Pow(2, rounds);
|
||||||
int output = 0;
|
int output = 0;
|
||||||
int totalTeams = 0;
|
int totalTeams = 1;
|
||||||
for (int i = 1; i < rounds; i++)
|
for (int i = 1; i <= rounds; i++)
|
||||||
{
|
{
|
||||||
totalTeams *= 2;
|
totalTeams *= 2;
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ namespace TrackerLibrary
|
|||||||
|
|
||||||
private static int FindNumberOfRounds(int teamCount)
|
private static int FindNumberOfRounds(int teamCount)
|
||||||
{
|
{
|
||||||
int output = 0;
|
int output = 1;
|
||||||
int val = 2;
|
int val = 2;
|
||||||
while (val < teamCount)
|
while (val < teamCount)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user