Tournament form is ready but matchup information
This commit is contained in:
@ -10,7 +10,7 @@ namespace TrackerLibrary.DataAccess
|
|||||||
PrizeModel CreatePrize(PrizeModel model);
|
PrizeModel CreatePrize(PrizeModel model);
|
||||||
PersonModel CreatePerson(PersonModel model);
|
PersonModel CreatePerson(PersonModel model);
|
||||||
TeamModel CreateTeam(TeamModel model);
|
TeamModel CreateTeam(TeamModel model);
|
||||||
TournamentModel CreateTournament(TournamentModel model);
|
void CreateTournament(TournamentModel model);
|
||||||
List<TeamModel> GetTeam_All();
|
List<TeamModel> GetTeam_All();
|
||||||
List<PersonModel> GetPerson_All();
|
List<PersonModel> GetPerson_All();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -89,7 +89,7 @@ namespace TrackerLibrary.DataAccess
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TournamentModel CreateTournament(TournamentModel model)
|
public void CreateTournament(TournamentModel model)
|
||||||
{
|
{
|
||||||
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(db)))
|
||||||
{
|
{
|
||||||
@ -99,8 +99,7 @@ namespace TrackerLibrary.DataAccess
|
|||||||
|
|
||||||
p = SaveTournamentEntries(model, connection, p);
|
p = SaveTournamentEntries(model, connection, p);
|
||||||
|
|
||||||
return model;
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static DynamicParameters SaveTournament(TournamentModel model, IDbConnection connection)
|
private static DynamicParameters SaveTournament(TournamentModel model, IDbConnection connection)
|
||||||
|
|||||||
@ -100,9 +100,22 @@ namespace TrackerLibrary.DataAccess
|
|||||||
{
|
{
|
||||||
return TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PeopleFile);
|
return TeamFile.FullFilePath().LoadFile().ConvertToTeamModels(PeopleFile);
|
||||||
}
|
}
|
||||||
public TournamentModel CreateTournament(TournamentModel model)
|
public void CreateTournament(TournamentModel model)
|
||||||
{
|
{
|
||||||
List<TournamentModel> tournaments = TournamentFile.FullFilePath().LoadFile().ConvertToTournamentModels();
|
List<TournamentModel> tournaments = TournamentFile
|
||||||
|
.FullFilePath()
|
||||||
|
.LoadFile()
|
||||||
|
.ConvertToTournamentModels(TeamFile, PeopleFile, PrizesFile);
|
||||||
|
|
||||||
|
int currentId = 1;
|
||||||
|
if (tournaments.Count > 0)
|
||||||
|
{
|
||||||
|
currentId = tournaments.OrderByDescending(x => x.Id).First().Id + 1;
|
||||||
|
}
|
||||||
|
model.Id = currentId;
|
||||||
|
tournaments.Add(model);
|
||||||
|
|
||||||
|
tournaments.SaveToTournamentFile(TournamentFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -47,7 +47,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
|||||||
public static List<PersonModel> ConvertToPersonModels(this List<string> lines)
|
public static List<PersonModel> ConvertToPersonModels(this List<string> lines)
|
||||||
{
|
{
|
||||||
List<PersonModel> output = new List<PersonModel>();
|
List<PersonModel> output = new List<PersonModel>();
|
||||||
foreach(string line in lines)
|
foreach (string line in lines)
|
||||||
{
|
{
|
||||||
string[] cols = line.Split(',');
|
string[] cols = line.Split(',');
|
||||||
PersonModel p = new PersonModel();
|
PersonModel p = new PersonModel();
|
||||||
@ -78,7 +78,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
|||||||
|
|
||||||
string[] personIds = cols[2].Split('|');
|
string[] personIds = cols[2].Split('|');
|
||||||
|
|
||||||
foreach(string id in personIds)
|
foreach (string id in personIds)
|
||||||
{
|
{
|
||||||
t.TeamMembers.Add(people.Where(x => x.Id == int.Parse(id)).First());
|
t.TeamMembers.Add(people.Where(x => x.Id == int.Parse(id)).First());
|
||||||
}
|
}
|
||||||
@ -90,9 +90,48 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<TournamentModel> ConvertToTournamentModels(this List<string> lines)
|
public static List<TournamentModel> ConvertToTournamentModels(
|
||||||
|
this List<string> lines,
|
||||||
|
string teamFileName,
|
||||||
|
string peopleFileName,
|
||||||
|
string prizesFileName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
|
// id = 0
|
||||||
|
// TournamentName = 1
|
||||||
|
// EntryFee = 2
|
||||||
|
// EnteredTeams = 3
|
||||||
|
// Prizes = 4
|
||||||
|
// Rounds = 5
|
||||||
|
|
||||||
// id, TournamentName, EntryFee, (id|id|id - entered teams), (id|id|id - entered prizes), (rounds - id^id^id|id^id^id|id^id^id)
|
// id, TournamentName, EntryFee, (id|id|id - entered teams), (id|id|id - entered prizes), (rounds - id^id^id|id^id^id|id^id^id)
|
||||||
|
List<TournamentModel> output = new List<TournamentModel>();
|
||||||
|
List<TeamModel> teams = teamFileName.FullFilePath().LoadFile().ConvertToTeamModels(peopleFileName);
|
||||||
|
List<PrizeModel> prizes = prizesFileName.FullFilePath().LoadFile().ConvertToPrizeModels();
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
string[] cols = line.Split(',');
|
||||||
|
TournamentModel tm = new TournamentModel();
|
||||||
|
tm.Id = int.Parse(cols[0]);
|
||||||
|
tm.TournamentName = cols[1];
|
||||||
|
tm.EntryFee = decimal.Parse(cols[2]);
|
||||||
|
string[] teamIds = cols[3].Split('|');
|
||||||
|
foreach (string teamId in teamIds)
|
||||||
|
{
|
||||||
|
tm.EnteredTeams.Add(teams.Where(x => x.Id == int.Parse(teamId)).First());
|
||||||
|
}
|
||||||
|
string[] prizeIds = cols[4].Split('|');
|
||||||
|
foreach (string prizeId in prizeIds)
|
||||||
|
{
|
||||||
|
tm.Prizes.Add(prizes.Where(x => x.Id == int.Parse(prizeId)).First());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capture rounds information
|
||||||
|
|
||||||
|
output.Add(tm);
|
||||||
|
|
||||||
|
}
|
||||||
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveToPrizeFile(this List<PrizeModel> models, string fileName)
|
public static void SaveToPrizeFile(this List<PrizeModel> models, string fileName)
|
||||||
@ -106,10 +145,10 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
|||||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void SaveToPeopleFile(this List<PersonModel> models, string fileName)
|
public static void SaveToPeopleFile(this List<PersonModel> models, string fileName)
|
||||||
{
|
{
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
foreach(PersonModel p in models)
|
foreach (PersonModel p in models)
|
||||||
{
|
{
|
||||||
lines.Add($"{p.Id},{p.FirstName},{p.LastName},{p.EmailAddress},{p.CellPhoneNumber}");
|
lines.Add($"{p.Id},{p.FirstName},{p.LastName},{p.EmailAddress},{p.CellPhoneNumber}");
|
||||||
}
|
}
|
||||||
@ -121,7 +160,7 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
|||||||
public static void SaveToTeamFile(this List<TeamModel> models, string fileName)
|
public static void SaveToTeamFile(this List<TeamModel> models, string fileName)
|
||||||
{
|
{
|
||||||
List<string> lines = new List<string>();
|
List<string> lines = new List<string>();
|
||||||
foreach(TeamModel t in models)
|
foreach (TeamModel t in models)
|
||||||
{
|
{
|
||||||
lines.Add($"{t.Id},{t.TeamName},{ConvertPeopleListToString(t.TeamMembers)}");
|
lines.Add($"{t.Id},{t.TeamName},{ConvertPeopleListToString(t.TeamMembers)}");
|
||||||
}
|
}
|
||||||
@ -129,14 +168,96 @@ namespace TrackerLibrary.DataAccess.TextHelpers
|
|||||||
File.WriteAllLines(fileName.FullFilePath(), lines);
|
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string ConvertPeopleListToString(List<PersonModel> people)
|
public static void SaveToTournamentFile(this List<TournamentModel> models, string fileName)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
List<string> lines = new List<string>();
|
||||||
|
foreach (TournamentModel tm in models)
|
||||||
|
{
|
||||||
|
lines.Add($@"{tm.Id},
|
||||||
|
{tm.TournamentName},
|
||||||
|
{tm.EntryFee},
|
||||||
|
{ConvertTeamListToString(tm.EnteredTeams)},
|
||||||
|
{ConvertPrizeListToString(tm.Prizes)},
|
||||||
|
{ConvertRoundListToString(tm.Rounds)}");
|
||||||
|
}
|
||||||
|
|
||||||
|
File.WriteAllLines(fileName.FullFilePath(), lines);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ConvertRoundListToString(List<List<Models.MatchupModel>> rounds)
|
||||||
|
{
|
||||||
|
// (rounds - id^id^id|id^id^id|id^id^id)
|
||||||
string output = "";
|
string output = "";
|
||||||
if (people.Count==0)
|
if (rounds.Count == 0)
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
foreach(PersonModel p in people)
|
foreach (List<MatchupModel> r in rounds)
|
||||||
|
{
|
||||||
|
output += $"{ConvertMatchupListToString(r)}|";
|
||||||
|
}
|
||||||
|
|
||||||
|
output = output.Substring(0, output.Length - 1);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ConvertMatchupListToString(List<MatchupModel> matchups)
|
||||||
|
{
|
||||||
|
string output = "";
|
||||||
|
if (matchups.Count == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
foreach (MatchupModel p in matchups)
|
||||||
|
{
|
||||||
|
output += $"{p.Id}^";
|
||||||
|
}
|
||||||
|
|
||||||
|
output = output.Substring(0, output.Length - 1);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ConvertPrizeListToString(List<PrizeModel> prizes)
|
||||||
|
{
|
||||||
|
string output = "";
|
||||||
|
if (prizes.Count == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
foreach (PrizeModel p in prizes)
|
||||||
|
{
|
||||||
|
output += $"{p.Id}|";
|
||||||
|
}
|
||||||
|
|
||||||
|
output = output.Substring(0, output.Length - 1);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ConvertTeamListToString(List<TeamModel> teams)
|
||||||
|
{
|
||||||
|
string output = "";
|
||||||
|
if (teams.Count == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
foreach (TeamModel t in teams)
|
||||||
|
{
|
||||||
|
output += $"{t.Id}|";
|
||||||
|
}
|
||||||
|
|
||||||
|
output = output.Substring(0, output.Length - 1);
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static string ConvertPeopleListToString(List<PersonModel> people)
|
||||||
|
{
|
||||||
|
string output = "";
|
||||||
|
if (people.Count == 0)
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
foreach (PersonModel p in people)
|
||||||
{
|
{
|
||||||
output += $"{p.Id}|";
|
output += $"{p.Id}|";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,10 @@ namespace TrackerLibrary.Models
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class MatchupModel
|
public class MatchupModel
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// The unique identifier for the matchup
|
||||||
|
/// </summary>
|
||||||
|
public int Id { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The set of teams that were involved in this match.
|
/// The set of teams that were involved in this match.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -124,7 +124,7 @@ namespace TrackerUI
|
|||||||
tm.Prizes = selectedPrizes;
|
tm.Prizes = selectedPrizes;
|
||||||
tm.EnteredTeams = selectedTeams;
|
tm.EnteredTeams = selectedTeams;
|
||||||
|
|
||||||
// Wireup our matchups
|
// TODO Wireup our matchups
|
||||||
|
|
||||||
// Finally create the tournament entry
|
// Finally create the tournament entry
|
||||||
// Create all of the prizes entries
|
// Create all of the prizes entries
|
||||||
|
|||||||
Reference in New Issue
Block a user