Nu skickar vi mail till deltagarna !
This commit is contained in:
@ -27,6 +27,7 @@ namespace TrackerLibrary
|
||||
|
||||
public static void UpdateTournamentResults(TournamentModel model)
|
||||
{
|
||||
int startingRound = model.CheckCurrentRound();
|
||||
List<MatchupModel> toScore = new List<MatchupModel>();
|
||||
|
||||
foreach (List<MatchupModel> round in model.Rounds)
|
||||
@ -45,7 +46,78 @@ namespace TrackerLibrary
|
||||
AdvanceWinners(toScore, model);
|
||||
|
||||
toScore.ForEach(x => GlobalConfig.Connection.UpdateMatchup(x));
|
||||
int endigRound = model.CheckCurrentRound();
|
||||
if (endigRound > startingRound)
|
||||
{
|
||||
model.AlertUsersToNewRound();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AlertUsersToNewRound(this TournamentModel model)
|
||||
{
|
||||
int currentRoundNumber = model.CheckCurrentRound();
|
||||
List<MatchupModel> currentRound = model.Rounds.Where(x => x.First().MatchupRound == currentRoundNumber).First();
|
||||
foreach (MatchupModel matchup in currentRound)
|
||||
{
|
||||
foreach (MatchupEntryModel me in matchup.Entries)
|
||||
{
|
||||
foreach (PersonModel p in me.TeamCompeting.TeamMembers)
|
||||
{
|
||||
AlertPersonToNewRound(p, me.TeamCompeting.TeamName, matchup.Entries.Where(x => x.TeamCompeting != me.TeamCompeting).FirstOrDefault());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void AlertPersonToNewRound(PersonModel p, string teamName, MatchupEntryModel competitor)
|
||||
{
|
||||
if (p.EmailAddress.Length == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> to = new List<string>();
|
||||
string subject;
|
||||
StringBuilder body = new StringBuilder();
|
||||
|
||||
if (competitor != null)
|
||||
{
|
||||
subject = $"You have a new matchup with {competitor.TeamCompeting.TeamName}";
|
||||
|
||||
body.AppendLine("<h1>You Have a new matchup</h1>");
|
||||
body.Append("<strong>Competitor: </strong>");
|
||||
body.Append(competitor.TeamCompeting.TeamName);
|
||||
body.AppendLine();
|
||||
body.AppendLine();
|
||||
body.AppendLine("Have a great time!");
|
||||
body.AppendLine("~Tournament Tracker");
|
||||
}
|
||||
else
|
||||
{
|
||||
subject = "You have a bye week this round";
|
||||
|
||||
body.AppendLine("Enjoy your round off!");
|
||||
body.AppendLine("~Tournament Tracker");
|
||||
}
|
||||
|
||||
to.Add(p.EmailAddress);
|
||||
|
||||
|
||||
EmailLogic.SendEmail( to, subject, body.ToString()); ;
|
||||
}
|
||||
|
||||
private static int CheckCurrentRound(this TournamentModel model)
|
||||
{
|
||||
int output = 1;
|
||||
foreach (List<MatchupModel> round in model.Rounds)
|
||||
{
|
||||
if (round.All(x => x.Winner != null))
|
||||
{
|
||||
output += 1;
|
||||
}
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
private static void AdvanceWinners(List<MatchupModel> models, TournamentModel tournament)
|
||||
@ -120,21 +192,6 @@ namespace TrackerLibrary
|
||||
}
|
||||
}
|
||||
|
||||
//if (teamOneScore > teamTwoScore)
|
||||
//{
|
||||
// // Team one winns
|
||||
// m.Winner = m.Entries[0].TeamCompeting;
|
||||
//}
|
||||
//else
|
||||
// if (teamTwoScore > teamOneScore)
|
||||
//{
|
||||
// // Team one winns
|
||||
// m.Winner = m.Entries[1].TeamCompeting;
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// MessageBox.Show("I dont handle tie games.");
|
||||
//}
|
||||
}
|
||||
|
||||
private static void CreateOtherRounds(TournamentModel model, int rounds)
|
||||
|
||||
Reference in New Issue
Block a user