private static string BuildLeagueTable(Season season) { var WeeksSoFar = season.Weeks.WeeksSoFar(); StringBuilder sb = new StringBuilder(); sb.Append("<table style='font-size:12px;border-collapse:collapse' cellspacing='5' cellpadding='5'>"); sb.Append("<tr style='background:#FFFCD6'>"); sb.Append("<th colspan='2'>Week Start Date</th>"); foreach (var Week in WeeksSoFar) { sb.Append("<th style='text-align:right'>" + Week.WeekStarts.ordinalDateMonth() + "</th>"); } sb.Append("<th rowspan='2'>Total</th>"); sb.Append("</tr>"); sb.Append("<tr style='background:#FFFCD6'>"); sb.Append("<th colspan='2'>Players / Week</th>"); for (var j = 1; j <= WeeksSoFar.Count(); j++) { sb.Append("<th style='text-align:right'>" + string.Format("Week #{0}", j) + "</th>"); } sb.Append("</tr>"); int i = 1; // for each players foreach (var p in season.GetLivePlayers().OrderByDescending(x=>x.CurrentTotalPoints(season))){ var GetPlayersPoints = season.GetPlayerPoints(p); sb.Append(string.Format("<tr{0}>", i % 2 == 0 ? "" : " style='background:#eeeeee'")); sb.Append("<td>" + string.Format("{0}#", i) + "</td>"); sb.Append("<td>" + p.Name + "</a></td>"); //for each week foreach(var pts in GetPlayersPoints){ sb.Append("<td style='text-align:right'>" + pts + "</td>"); } sb.Append("<td style='text-align:right'>" + GetPlayersPoints.Sum() + "</td>"); sb.Append("</tr>"); i += 1; } sb.Append("</table>"); return sb.ToString(); }
public static int SendNewPredictionsEmail(Season season) { var StartTime = DateTime.Now; var ThisWeek = season.GetCurrentWeekSeason(); //Get league and week matches tables var LeagueTable = BuildLeagueTable(season); var WeekTable = BuildWeekMatches(ThisWeek); //SeasonWeek Name var SeasonText = string.Format("{0}: Season running from {0} to {1}", season.League.Name, season.SeasonStarts.ordinalDateMonth(), season.SeasonEnd.ordinalDateMonth()); var WeekText = string.Format("Weeks cut off date {0} at {1}", ThisWeek.WeekCutOff.ordinalDateMonth(), ThisWeek.WeekCutOff.ToShortTimeString()); int EmailCount = 0; //TODO: this will probably crash at the end/start of a season! foreach (var player in season.GetLivePlayers()) { //need to change the week to last week or list of predictions var GetPlayersLastWeek = BuildPlayersLastWeekMatches(season, player); StringBuilder body = new StringBuilder(); body.Append("Dear " + player.Name + "<br />"); body.Append("<p>Here are your results for the week just gone and the matches for this weeks predictions.</p>"); if(!string.IsNullOrEmpty(LeagueTable)){ body.Append("<h2>League Table <a href='http://www.britboxing.co.uk/season'>View Online</a></h2/>"); body.Append(LeagueTable + "<br/>"); } if (!string.IsNullOrEmpty(WeekTable)) { body.Append("<h2>This Weeks Matches <a href='http://www.britboxing.co.uk/boxingpredictionleague/addprediction'>Add Prediction</a></h2>"); body.Append(WeekTable + "<br/>"); } if (!string.IsNullOrEmpty(GetPlayersLastWeek)) { //Build their last weeks outcome results table body.Append("<h2>Your Last weeks score <a href='http://www.britboxing.co.uk/player'>View Dashboard</a></h2>"); body.Append(GetPlayersLastWeek + "<br/>"); } //ending of email body.Append("<p>Remember to get your predictions in for the week cut off</p>"); body.Append("<p>You can access your dashboard by clicking <a href='http://www.britboxing.co.uk/player'>here</a></p>"); body.Append("<h3>" + WeekText + "</h3>"); body.Append("<br/><br/> Regards <br/><br/>Steve<br/> Boxing Prediction League Admin"); //only send out first 3 if in test mode if (System.Configuration.ConfigurationSettings.AppSettings["LiveServer"] == "false" && EmailCount >= 3) { //dont send out more then 3 emails in test mode } else { //Send out email and incredment if successful if (Send(body.ToString(), player.User.Email, "*****@*****.**", string.Format("{0}: Results and the week of {0} matches", season.League.Name, ThisWeek.WeekStarts.ToLongDateString()))) { EmailCount += 1; } } } BuildAndSendAdminEmail("Monday Results and New Predictions", EmailCount, StartTime, DateTime.Now); return EmailCount; }