private static List <MatchupModel> CreateFirstRound(int bytes, List <TeamModel> teams) { List <MatchupModel> output = new List <MatchupModel>(); MatchupModel curr = new MatchupModel(); foreach (TeamModel team in teams) { curr.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); //use byes first //when there is any bye or when there are 2 entries //complete this MatchupModel, put it into output if (bytes > 0 || curr.Entries.Count > 1) { curr.MatchupRound = 1; output.Add(curr); curr = new MatchupModel(); if (bytes > 0) { bytes -= 1; } } } return(output); }
/// <summary> /// Creates the first round /// </summary> /// <param name="byes">auto win</param> /// <param name="teams">teams particpating in first round</param> /// <returns></returns> private static List <MatchupModel> CreateFirstRound(int byes, List <TeamModel> teams) { List <MatchupModel> output = new List <MatchupModel>(); MatchupModel currentMatchupModel = new MatchupModel(); foreach (TeamModel team in teams) { currentMatchupModel.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); if (byes > 0 || currentMatchupModel.Entries.Count > 1) { currentMatchupModel.MatchupRound = 1; //hardcoded because first round output.Add(currentMatchupModel); currentMatchupModel = new MatchupModel(); if (byes > 0) { //byes = byes - 1 byes -= 1; } } } return(output); }
private static List <MatchupModel> CreateFirstRound(int byes, List <TeamModel> teams) { var firstRound = new List <MatchupModel>(); var match = new MatchupModel(); foreach (var team in teams) { match.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); if (byes > 0 || match.Entries.Count > 1) { match.MatchupRound = 1; firstRound.Add(match); match = new MatchupModel(); if (byes > 0) { byes -= 1; } } } return(firstRound); }
private static void CreateRounds(TournamentModel tournament, int rounds) { var round = 2; var previousRound = tournament.Rounds[0]; var currRound = new List <MatchupModel>(); var currMatchup = new MatchupModel(); while (round <= rounds) { foreach (var match in previousRound) { currMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = match }); if (currMatchup.Entries.Count > 1) { currMatchup.MatchupRound = rounds; currRound.Add(currMatchup); currMatchup = new MatchupModel(); } } tournament.Rounds.Add(currRound); previousRound = currRound; currRound = new List <MatchupModel>(); round += 1; } }
/// <summary> /// Creates the first round and the matchups. /// </summary> /// <param name="numberOfByes">Number of bye rounds in the tournament.</param> /// <param name="model">A list of teams.</param> /// <returns>The first round of the tournament.</returns> private static List <MatchupModel> CreateFirstRound(int numberOfByes, List <TeamModel> model) { List <MatchupModel> output = new List <MatchupModel>(); MatchupModel current = new MatchupModel(); foreach (TeamModel team in model) { current.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); if (numberOfByes > 0 || current.Entries.Count > 1) { current.MatchupRound = 1; output.Add(current); current = new MatchupModel(); if (numberOfByes > 0) { numberOfByes -= 1; } } } return(output); }
/// <summary> /// Function creates rounds of the tournament that have to be played /// </summary> private static void CreateOtherRounds(TournamentModel model, int rounds) { //Number of current round int round = 2; List <MatchupModel> previousRound = model.Rounds[0]; List <MatchupModel> currRound = new List <MatchupModel>(); MatchupModel currMatchup = new MatchupModel(); while (round <= rounds) { foreach (MatchupModel matchup in previousRound) { currMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = matchup }); //If there are 2 teams in MatchupEntry, reset Add it to current Round list, and reset current Matchup if (currMatchup.Entries.Count > 1) { currMatchup.MatchupRound = round; currRound.Add(currMatchup); currMatchup = new MatchupModel(); } } // When adding entries for current round is done, add this round to list of rounds // and head to creating next one, after reseting current Round variable model.Rounds.Add(currRound); previousRound = currRound; round++; currRound = new List <MatchupModel>(); } }
private static void CreateOtherRounds(TournamentModel model, int rounds) { int round = 2; List <MatchupModel> previousRound = model.Rounds[0]; //Grab the first list of MatchUpModel in our Rounds variable List <MatchupModel> currRound = new List <MatchupModel>(); MatchupModel currMatchup = new MatchupModel(); while (round <= rounds) { foreach (MatchupModel match in previousRound) { currMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = match }); //Parent from the previous round! if (currMatchup.Entries.Count > 1) //If we have more than one entry { currMatchup.MatchupRound = round; currRound.Add(currMatchup); currMatchup = new MatchupModel(); } } model.Rounds.Add(currRound); previousRound = currRound; currRound = new List <MatchupModel>(); round += 1; } }
private static List <MatchupModel> CreateFirstRound(int byes, List <TeamModel> teams) { List <MatchupModel> output = new List <MatchupModel>(); MatchupModel curr = new MatchupModel(); foreach (TeamModel team in teams) { curr.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); if (byes > 0 || curr.Entries.Count > 1) { curr.MatchupRound = 1; output.Add(curr); curr = new MatchupModel(); if (byes > 0) { byes -= 1; } } } return(output); }
private static void CreateOtherRounds(TournamentModel model, int rounds) { int round = 2; List <MatchupModel> previousRound = model.Rounds[0]; List <MatchupModel> currentRound = new List <MatchupModel>(); MatchupModel currMatchup = new MatchupModel(); while (round <= rounds) { foreach (MatchupModel match in previousRound) { currMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = match }); if (currMatchup.Entries.Count > 1) { currMatchup.MatchupRound = round; currentRound.Add(currMatchup); currMatchup = new MatchupModel(); } } model.Rounds.Add(currentRound); previousRound = currentRound; currentRound = new List <MatchupModel>(); round += 1; } }
/// <summary> /// Function creates first round of tournament /// </summary> private static List <MatchupModel> CreateFirstRound(int byes, List <TeamModel> teams) { List <MatchupModel> output = new List <MatchupModel>(); MatchupModel curr = new MatchupModel(); foreach (TeamModel team in teams) { curr.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); if (byes > 0 || curr.Entries.Count > 1) { //set round number curr.MatchupRound = 1; // if byes ended this matchup, decrease it's value if (byes > 0) { byes--; } //add new Matchup Entry to output output.Add(curr); //Reset Matchup curr = new MatchupModel(); } } return(output); }
// First round is special: It might have dummy teams (byes) to complete the num of teams to 2^n. private static List <MatchupModel> CreateFirstRound(int byes, List <TeamModel> teams) { List <MatchupModel> output = new List <MatchupModel>(); MatchupModel curr = new MatchupModel(); foreach (TeamModel team in teams) { curr.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); // If only one team is added yet and we have some byes then a bye will be added to the matchup (instead of a real team), no more teams needs to be added. // If there are already 2 teams then matchup is ready, no more teams needs to be added. if (byes > 0 || curr.Entries.Count > 1) { curr.MatchupRound = 1; output.Add(curr); curr = new MatchupModel(); if (byes > 0) { byes--; } } } return(output); }
private static void CompleteTournament(TournamentModel tournament) { GlobalConfig.Connections.CompleteTournament(tournament); // Announce tournament results and prize distributions MatchupModel lastMatchup = tournament.Rounds.Last().First(); TeamModel winner = lastMatchup.Winner; TeamModel runnerUp = lastMatchup.Entries.Where(x => x.TeamCompeting != winner).First().TeamCompeting; string subject = $"{tournament.TournamentName} has concluded!"; StringBuilder body = new StringBuilder(); body.AppendLine("<h2>WE HAVE A WINNER!</h2>"); body.AppendLine($"<p>Congratulations to <b>{winner.TeamName}</b> on a great tournament.</p>"); body.AppendLine("<br>"); if (tournament.Prizes.Count > 0) { decimal totalIncome = tournament.EnteredTeams.Count * tournament.EntryFee; PrizeModel firstPlacePrize = tournament.Prizes.Where(x => x.PlaceNumber == 1).FirstOrDefault(); PrizeModel secondPlacePrize = tournament.Prizes.Where(x => x.PlaceNumber == 2).FirstOrDefault(); if (firstPlacePrize != null) { decimal winnerPrizeAmt = CalculatePayout(firstPlacePrize, totalIncome); body.AppendLine($"<p>{winner.TeamName} will receive ${string.Format("{0:0.00}", winnerPrizeAmt)}!</p>"); } if (secondPlacePrize != null) { decimal runnerUpPrizeAmt = CalculatePayout(secondPlacePrize, totalIncome); body.AppendLine($"<p>{runnerUp.TeamName} will receive ${string.Format("{0:0.00}", runnerUpPrizeAmt)}.</p>"); } if (firstPlacePrize != null || secondPlacePrize != null) { body.AppendLine("<br>"); } } body.AppendLine("<p>Hope everyone had a great time.</p>"); body.AppendLine("<p>~Tournament Tracker</p>"); List <string> bcc = new List <string>(); foreach (TeamModel t in tournament.EnteredTeams) { foreach (PersonModel player in t.TeamMembers) { bcc.Add(player.Email); } } EmailLogic.SendEmail(new List <string>(), bcc, subject, body.ToString()); // Complete tournament tournament.CompleteTournament(); }
private static void NotifyMatchupEntries(this MatchupModel matchup, string tournamentName) { matchup.Entries.ForEach(e => e.TeamCompeting.TeamMembers .ForEach(mb => mb.NotifyPersonToMatchup( tournamentName, matchup.MatchupRound, e.TeamCompeting, matchup.Entries.FirstOrDefault(me => me.TeamCompeting != e.TeamCompeting)?.TeamCompeting))); }
private static void CompleteTournament(this TournamentModel tournament) { GlobalConfig.Connection.DeactivateTournament(tournament); MatchupModel finalMatchup = tournament.Rounds.Last().Matchups.First(); TeamModel winner = finalMatchup.Winner; TeamModel runnerUp = finalMatchup.Entries.First(e => e.TeamCompeting != winner).TeamCompeting; decimal winnerPrize = 0; decimal runnerUpPrize = 0; if (tournament.Prizes.Count > 0) { decimal totalIncome = tournament.EnteredTeams.Count * tournament.EntryFee; PrizeModel firstPlacePrize = tournament.Prizes.FirstOrDefault(p => p.PlaceNumber == 1); PrizeModel secondPlacePrize = tournament.Prizes.FirstOrDefault(p => p.PlaceNumber == 2); winnerPrize = firstPlacePrize?.CalculatePrizePayout(totalIncome) ?? 0; runnerUpPrize = secondPlacePrize?.CalculatePrizePayout(totalIncome) ?? 0; } string subject = $"In {tournament.TournamentName}, {winner.TeamName} has won!"; StringBuilder body = new StringBuilder(); body.AppendLine("<h1>We have a Winner!</h1>"); body.AppendLine("<p>Congratulations to out winner on a great tournament.</p>"); body.AppendLine("<br />"); if (winnerPrize > 0) { body.AppendLine($"<p>{winner.TeamName} will receive ${winnerPrize}</p>"); } if (runnerUpPrize > 0) { body.AppendLine($"<p>{runnerUp.TeamName} will receive {runnerUpPrize} as runner up</p>"); } body.AppendLine("<p>Thanks to everyone for participating!</p>"); body.AppendLine("<p>~Tournament Tracker</p>"); List <string> bcc = new List <string>(); tournament.EnteredTeams.ForEach(et => et.TeamMembers.Where(mb => !string.IsNullOrEmpty(mb.EmailAddress)).ToList().ForEach(p => bcc.Add(p.EmailAddress))); EmailLogic.SendEmail(new List <string>(), bcc, subject, body.ToString()); }
/// <summary> /// Advance the winning team of the given matchup to the next round /// (i.e. set the winning team as the team competing in the following round). /// </summary> /// <param name="matchup">The matchup with a winner to advance.</param> /// <param name="tournament">Tournament in which the matchup is part of.</param> private static void AdvanceWinner(MatchupModel matchup, TournamentModel tournament) { for (int i = 1; i < tournament.Rounds.Count; i++) { foreach (MatchupModel rm in tournament.Rounds[i]) { foreach (MatchupEntryModel me in rm.Entries) { if (me.ParentMatchup == matchup) { me.TeamCompeting = matchup.Winner; GlobalConfig.Connections.UpdateMatchup(rm); return; } } } } }
public static void UpdateMatchupResults(this MatchupModel matchup, double scoreTeamOne, double scoreTeamTwo) { if (matchup.Entries.Count == 1) { return; } bool parseValid = bool.TryParse(ConfigurationManager.AppSettings["greaterWins"], out bool greaterWins); if (!parseValid) { greaterWins = true; } UpdateWinner(matchup, greaterWins, scoreTeamOne, scoreTeamTwo); GlobalConfig.Connection.UpdateMatchup(matchup); }
private static void CreateOtherRounds(TournamentModel model, int rounds) { int round = 2; List <MatchupModel> previousRound = model.Rounds[0]; // First round List <MatchupModel> currRound = new List <MatchupModel>(); MatchupModel currMatchup = new MatchupModel(); // round1 round2 round3 // ---- // match1 ---- // ---- // match3 ---- // ---- // match2 ---- // ---- while (round <= rounds) { // We create half as many matchups in the current round as in the previous one foreach (MatchupModel match in previousRound) { currMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = match }); // If both MatchupEntryModels are added for this matchup, then the matchup is ready to be added to the current round if (currMatchup.Entries.Count > 1) { currMatchup.MatchupRound = round; currRound.Add(currMatchup); currMatchup = new MatchupModel(); } } model.Rounds.Add(currRound); previousRound = currRound; currRound = new List <MatchupModel>(); round++; } }
public static void UpdateTournamentResults(TournamentModel tournament, MatchupModel matchupToUpdate) { int startingRound = GetCurrentRound(tournament); SetMatchupWinner(matchupToUpdate); GlobalConfig.Connections.UpdateMatchup(matchupToUpdate); AdvanceWinner(matchupToUpdate, tournament); int endingRound = GetCurrentRound(tournament); if (endingRound > tournament.Rounds.Count) { // last round is finished CompleteTournament(tournament); } else if (endingRound > startingRound) { tournament.AlertUsersToNewRound(); } }
private static void CreateOtherRounds(TournamentModel model, int rounds) { int round = 2; List <MatchupModel> previousRound = model.Rounds[0]; List <MatchupModel> currRound = new List <MatchupModel>(); MatchupModel currMatchup = new MatchupModel(); // Starting from round 2. If there are more then keep looping until all // rounds have matched up. while (round <= rounds) { // For each match in the previous round of matchups foreach (MatchupModel match in previousRound) { // Use that matchup as the parent matchup of this matchup entry. We don't // know who the winner from that matchup is, but we know who the parent matchup is. // So we put in an anonymous team in where only the parent matchup is known. currMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = match }); if (currMatchup.Entries.Count > 1) { currMatchup.MatchupRound = round; currRound.Add(currMatchup); currMatchup = new MatchupModel(); } } // Add the new list of matchups to the tournament model.Rounds.Add(currRound); // Make the completed list the new previous list previousRound = currRound; // Reset the current list. currRound = new List <MatchupModel>(); // Change the round number identity. round++; } }
// 4. Create every round after the 1st round. We're dividing by 2 now. 8/2 = 4, 4/2 = 2 private static void CreateOtherRounds(TournamentModel model, int totalTournamentRounds) { // Represents the current round that we're on int currentRoundCounter = 2; // We have to work on the previous round to get the values for the current round List <MatchupModel> previousRound = model.Rounds[0]; // This is a List because a Round is a List<List<MatchupModel>> List <MatchupModel> currentRound = new List <MatchupModel>(); // MatchupModel currentMatchup = new MatchupModel(); // While 2 is less than or equal to our total number of rounds while (currentRoundCounter <= totalTournamentRounds) { // foreach (MatchupModel match in previousRound) { // Assigning parent matchup from the previous round currentMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = match }); // if (currentMatchup.Entries.Count > 1) { currentMatchup.MatchupRound = currentRoundCounter; currentRound.Add(currentMatchup); // clearing out the model now that it has been added currentMatchup = new MatchupModel(); } } model.Rounds.Add(currentRound); previousRound = currentRound; currentRound = new List <MatchupModel>(); currentRoundCounter += 1; } }
/// <summary> /// Create all the rounds, except the first one /// </summary> /// <param name="model">Tournament model</param> /// <param name="rounds">Number of rounds of the tournament</param> private static void CreateOtherRounds(TournamentModel model, int rounds) { // the current round we are on int round = 2; // grab the first list of Matchup model // initially this is the first round List <MatchupModel> previousRound = model.Rounds[0]; List <MatchupModel> currentRound = new List <MatchupModel>(); MatchupModel currentMatchup = new MatchupModel(); while (round <= rounds) { // loop through the previous round // the first person from the competing teams gets the bye-team // Eg from Matchup System logic - Sue VS Bye foreach (MatchupModel match in previousRound) { // I don't know the score or the team currentMatchup.Entries.Add(new MatchupEntryModel { ParentMatchup = match }); if (currentMatchup.Entries.Count > 1) { currentMatchup.MatchupRound = round; currentRound.Add(currentMatchup); currentMatchup = new MatchupModel(); } } model.Rounds.Add(currentRound); previousRound = currentRound; currentRound = new List <MatchupModel>(); round += 1; } }
/// <summary> /// Updates a selected matchup and saves to the database. /// </summary> /// <param name="model">Model to update and save.</param> public void UpdateMatchup(MatchupModel model) { // Connect to database. using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnString(Db))) { // Declare dapper dynamic parameters varaible. var p = new DynamicParameters(); // if the matchup has a winner //add the matchup id and winner id to dapper DP. if (model.Winner != null) { p.Add("@id", model.Id); p.Add("@WinnerId", model.WinnerId); // Execute stored procedure to update the matchups. connection.Execute("dbo.spMatchups_Update", p, commandType: CommandType.StoredProcedure); } // For each matchup entry in the matchup model // loop through to see if we have 2 teams. foreach (MatchupEntryModel me in model.Entries) { // if we have 2 teams. if (me.TeamCompeting != null) { // add id, team competitng id and score to DP variable. p = new DynamicParameters(); p.Add("@id", me.Id); p.Add("@TeamCompetingId", me.TeamCompeting.Id); p.Add("@Score", me.Score); // Execute stored procedure to update the matchup entries. connection.Execute("dbo.spMatchupEntries_Update", p, commandType: CommandType.StoredProcedure); } } } }
/// <summary> /// Generates the body of an email to alert participating players of their matchup /// for the new round, tailored to the team competing in the given matchup entry. /// </summary> /// <returns>A HTML-formatted string for the body of an email.</returns> private static string NewRoundEntryBody(MatchupModel matchup, MatchupEntryModel me) { StringBuilder body = new StringBuilder(); TeamModel competitor = matchup.Entries.Where(x => x.TeamCompeting != me.TeamCompeting).FirstOrDefault()?.TeamCompeting; if (competitor is null) { body.AppendLine("<h2>You have a bye week this round!</h2>"); body.AppendLine("<p>Enjoy your round off.</p>"); body.AppendLine("<p>~Tournament Tracker</p>"); } else { body.AppendLine("<h2>You have a new matchup!</h2>"); body.Append("<p><strong>Competitor: </strong>"); body.AppendLine(competitor.TeamName + "</p>"); body.AppendLine("<p>Have a great time.</p>"); body.AppendLine("<p>~Tournament Tracker</p>"); } return(body.ToString()); }
// 3. Create a 1st round of matchups since it's already from a randomized list of even teams. We already have the information // The first round is unique because we already know who the teams are private static List <MatchupModel> CreateFirstRound(int byeWeeks, List <TeamModel> teams) { List <MatchupModel> firstRoundMatchups = new List <MatchupModel>(); // One MatchupModel MatchupModel currentMatchup = new MatchupModel(); foreach (TeamModel team in teams) { // Remember, Entries is a List<>. // Therefore a team is only half of a MatchupModel // Adding one entry currentMatchup.Entries.Add(new MatchupEntryModel { TeamCompeting = team }); // if either is true, we're done with this current matchup // a byeweek will be the second team || we already have 2 teams if (byeWeeks > 0 || currentMatchup.Entries.Count > 1) { // "1" is hardcoded because we're creating the 1st round, hence the method name currentMatchup.MatchupRound = 1; firstRoundMatchups.Add(currentMatchup); // Reusing the variable now that it has been added to our output list currentMatchup = new MatchupModel(); // if we still have bye weeks to distribute if (byeWeeks > 0) { // Make sure you subtract the byeWeek we just used. byeWeeks -= 1; } } } return(firstRoundMatchups); }
private static void UpdateWinner(MatchupModel matchup, bool greaterWins, double scoreTeamOne, double scoreTeamTwo) { if (greaterWins) { if (scoreTeamOne > scoreTeamTwo) { matchup.Winner = matchup.Entries[0].TeamCompeting; } else if (scoreTeamTwo > scoreTeamOne) { matchup.Winner = matchup.Entries[1].TeamCompeting; } else { throw new Exception("No ties are allowed"); } } else { if (scoreTeamOne < scoreTeamTwo) { matchup.Winner = matchup.Entries[0].TeamCompeting; } else if (scoreTeamTwo < scoreTeamOne) { matchup.Winner = matchup.Entries[1].TeamCompeting; } else { throw new Exception("No ties are allowed"); } } matchup.Entries[0].Score = scoreTeamOne; matchup.Entries[1].Score = scoreTeamTwo; }
public static List <List <MatchupModel> > CreateRounds(TournamentModel model) { // Get randomized list of teams List <TeamModel> randomizedTeams = model.EnteredTeams.OrderBy(x => Guid.NewGuid()).ToList(); // Get number of rounds int rounds = (int)(Math.Ceiling(Math.Log((double)randomizedTeams.Count, 2))); // Get number of byes required int byes = (int)(Math.Pow(2, (double)(rounds - 1)) - randomizedTeams.Count); int matchups = (int)(Math.Pow(2, (double)rounds) - 1); int lastroundMatchupCountBuffer = 0; int lastroundMatchupCount = 0; int lastRoundMatchupListInd = 0; int randomTeamIndex = 0; bool endOfList = false; List <List <MatchupModel> > matchupModelsAllRounds = new List <List <MatchupModel> >(); List <MatchupModel> lastRoundMatchupList = new List <MatchupModel>(); // Start creating matchups for (int i = 0; i < rounds; i++) { List <MatchupModel> matchupModelsPerRound = new List <MatchupModel>(); if (i + 1 == 1) { for (int j = 0; j < (int)Math.Ceiling((double)randomizedTeams.Count / 2); j++) { // Create new MatchupModel MatchupModel matchupModel = new MatchupModel(); matchupModel.MatchupRound = i + 1; matchupModel.TournamentId = model.Id; // Add in DB and get id matchupModel = GlobalConfig.Connection.CreateMatchup(matchupModel); for (int k = 0; k < 2; k++)//Add two teams per Matchup { if (endOfList) { // Add byes to Matchups MatchupEntryModel matchupEntryModel = new MatchupEntryModel(); // Add null teams to matchups with bye matchupEntryModel.MatchupId = matchupModel.Id; matchupEntryModel.TournamentId = model.Id; GlobalConfig.Connection.CreateMatchupEntry(matchupEntryModel); matchupModel.Entries.Add(matchupEntryModel); } else { // Create MatchupEntry MatchupEntryModel matchupEntryModel = new MatchupEntryModel(); // Add teams to first round Matchups matchupEntryModel.MatchupId = matchupModel.Id; matchupEntryModel.TournamentId = model.Id; matchupEntryModel.TeamCompeting = randomizedTeams[randomTeamIndex]; GlobalConfig.Connection.CreateMatchupEntry(matchupEntryModel); matchupModel.Entries.Add(matchupEntryModel); if (randomizedTeams[randomTeamIndex] == randomizedTeams.Last()) { endOfList = true; } randomTeamIndex += 1; } } lastroundMatchupCountBuffer += 1; matchupModelsPerRound.Add(matchupModel); } } else { for (int j = 0; j < lastroundMatchupCount / 2; j++) { // Create new MatchupModel MatchupModel matchupModel = new MatchupModel(); matchupModel.MatchupRound = i + 1; matchupModel.TournamentId = model.Id; // Add in DB and get id matchupModel = GlobalConfig.Connection.CreateMatchup(matchupModel); for (int k = 0; k < 2; k++) { // Create blank MatchupEntries MatchupEntryModel matchupEntryModel = new MatchupEntryModel(); matchupEntryModel.MatchupId = matchupModel.Id; matchupEntryModel.TournamentId = model.Id; matchupEntryModel.ParentMatchup = lastRoundMatchupList[lastRoundMatchupListInd]; GlobalConfig.Connection.CreateMatchupEntry(matchupEntryModel); matchupModel.Entries.Add(matchupEntryModel); lastRoundMatchupListInd += 1; } lastroundMatchupCountBuffer += 1; matchupModelsPerRound.Add(matchupModel); } } matchupModelsAllRounds.Add(matchupModelsPerRound); lastroundMatchupCount = lastroundMatchupCountBuffer; lastRoundMatchupList = matchupModelsPerRound; } return(matchupModelsAllRounds); }
/// <summary> /// Updates a matchup to a text file. /// </summary> /// <param name="model">Model to update.</param> public void UpdateMatchup(MatchupModel model) { model.UpdateMatchupToFile(); }