public PlayerDashBoardViewModel(IEnumerable<League> leagues, Season currentSeason, IEnumerable<PlayerPredictionSummary> predictions, IEnumerable<PlayerPredictionSummary> LastWeekPredictions, Player playerProfile, Week LastWeek, Boolean IsViewingMyOwnPage, IQueryable<Notification> repnotifications) { LeagueSelections = leagues.ToDictionary((x => x.Name), x => x.Id.ToString()); CurrentSeasonText = string.Format("{0} - {1} to {2}", currentSeason.League.Name, currentSeason.SeasonStarts.ToLongDateString(), currentSeason.SeasonEnd.ToLongDateString()); ThisWeek = currentSeason.GetCurrentWeekSeason(); IsMyPage = IsViewingMyOwnPage; if (predictions != null) { PredictionsWithOutComes = predictions.Where(x => x.HasOutcome).OrderBy(y=>y.MatchDate); PredictionUpComingMatches = predictions.Where(x => !x.HasOutcome).OrderBy(y => y.MatchDate); ThisWeeksMotWId = ThisWeek != null && ThisWeek.MatchOfTheWeek != null ? ThisWeek.MatchOfTheWeek.Id : 0; } if (LastWeekPredictions != null) { PredictionsOfPreviousWeek = LastWeekPredictions.OrderBy(y => y.MatchDate); LastWeeksMotWId = LastWeek != null && LastWeek.MatchOfTheWeek != null ? LastWeek.MatchOfTheWeek.Id : 0; } //Build Players Table Points = currentSeason.Weeks.WeeksSoFar().Select(w => currentSeason.GetTotalPointsForAPlayersWeek(playerProfile, w)).ToList(); WeekNames = currentSeason.Weeks.WeeksSoFar().Select(x => x.WeekStarts.Day.ordinalNum() + " " + x.WeekStarts.ToString("MMM")).ToArray(); //set up notifications notifications = repnotifications.Take(3); AllPredictionsConfirmed = ThisWeek != null ? playerProfile.HasCompletedPredictions(ThisWeek) : true; }
public PredictionViewModel(Season currentSeason, Player currentLoggedInPlayer, IEnumerable<Comment> Comments) { LoggedInPlayer = currentLoggedInPlayer; Week week = currentSeason.GetCurrentWeekSeason(); CurrentWeekText = string.Format("This Week runs from {0} too {1}, This weeks cutoff for predictions is at {2} on the {3}", week.WeekStarts.ordinalDateShortDay(), week.WeekEnds.ordinalDateShortDay(), week.WeekCutOff.ToString("hh:mm tt"), week.WeekCutOff.ordinalDateShortDay()); ThisWeeksMatches = week.AllMatches().OrderBy(m =>m.MatchDate.Value); MatchOfTheWeek = week.MatchOfTheWeek; var PPs = new Dictionary<Player, IEnumerable<PlayerPrediction>>(); var PlayersWithCompletedPredictions = currentSeason.League.Players.Where(p => p.HasCompletedPredictions(week)); foreach (var p in PlayersWithCompletedPredictions.OrderByDescending(x=>x.CurrentTotalPoints(currentSeason))) { PPs.Add(p, p.GetPredictionsForThisWeek().OrderBy(m => m.Match.MatchDate.Value)); } PlayerPredictions = PPs; //comments CommentModel = new CommentingViewModel(7, week.Id, Comments.AsQueryable(), LoggedInPlayer); }
public PlayerPrediction(Player player, Match match, DateTime createdOn) : this() { Player = player; Match = match; CreatedOn = createdOn; }
public static int GetPlayerPositionChange(this Season query, Player player) { var LastWeekPos = GetPlayerLastWeekPosition(query, player); var Current = GetPlayerCurrentPosition(query, player); //last week was 3rd this week 1st so 3rd - 1st = up 2.... if was 1st now 3rd = -2 return LastWeekPos - Current; }
//Need to combind this and above atm only differences is the //GetTotalPointsForAPlayerLastWeeks function ... should get this when ordering and pass it in private static int GetPlayerLastWeekPosition(this Season query, IEnumerable<Player> PlayersOrderedByPts, Player player) { //find yourself and count int pos = 0; int MyPosition = 0; int PreviousPlayerPts = 10000; foreach (var p in PlayersOrderedByPts) { pos += 1; var PlayersPoints = query.GetTotalPointsForAPlayerLastWeeks(p); if (PlayersPoints < PreviousPlayerPts) { //if you don't match previous position then increment position up MyPosition = pos; PreviousPlayerPts = PlayersPoints; } if (p == player) { return MyPosition; } } //fail to find them so put them bottom? return pos; }
public SimplePlayer(Player player) { PlayerName = player.Name; CurrentChampion = player.IsCurrentChampion(); SeasonsWon = player.SeasonsWon.Count(); PlayerId = player.Id; //was a title holder if (player.SeasonsWon.Count() == 1 & CurrentChampion) { Credentials = string.Format("current BPL champion"); } else if (player.SeasonsWon.Count() == 1 & !CurrentChampion) { Credentials = string.Format("ex-BPL champion"); } else if (player.SeasonsWon.Count() > 0 & !CurrentChampion) { Credentials = string.Format("{0} times BPL champion", player.SeasonsWon.Count()); } else if (player.SeasonsWon.Count() > 0 & !CurrentChampion) { Credentials = string.Format("Current and {0} times BPL champion", player.SeasonsWon.Count()); } else { Credentials = "None"; } }
public BPLPlayerViewModel(IEnumerable<League> leagues, Season currentSeason, IEnumerable<PlayerPredictionSummary> predictions, IEnumerable<PlayerPredictionSummary> LastWeekPredictions, Player LoggedInPlayer, Week LastWeek) { LeagueSelections = leagues.ToDictionary((x => x.Name), x => x.Id.ToString()); CurrentSeasonText = string.Format("{0} - {1} to {2}", currentSeason.League.Name, currentSeason.SeasonStarts.ToLongDateString(), currentSeason.SeasonEnd.ToLongDateString()); ThisWeek = currentSeason.GetCurrentWeekSeason(); if (predictions != null) { PredictionsWithOutComes = predictions.Where(x => x.HasOutcome).OrderBy(y=>y.MatchDate); PredictionUpComingMatches = predictions.Where(x => !x.HasOutcome).OrderBy(y => y.MatchDate); ThisWeeksMotWId = ThisWeek != null && ThisWeek.MatchOfTheWeek != null ? ThisWeek.MatchOfTheWeek.Id : 0; } if (LastWeekPredictions != null) { PredictionsOfPreviousWeek = LastWeekPredictions.OrderBy(y => y.MatchDate); LastWeeksMotWId = LastWeek != null && LastWeek.MatchOfTheWeek != null ? LastWeek.MatchOfTheWeek.Id : 0; } //Build Players Table Points = currentSeason.Weeks.WeeksSoFar().Select(w => currentSeason.GetTotalPointsForAPlayersWeek(LoggedInPlayer, w)).ToList(); WeekNames = currentSeason.Weeks.WeeksSoFar().Select(x => x.WeekStarts.Day.ordinalNum() + " " + x.WeekStarts.ToString("MMM")).ToArray(); AllPredictionsConfirmed = ThisWeek != null ? LoggedInPlayer.HasCompletedPredictions(ThisWeek) : true; }
public CommentingViewModel(int itemtype, int itemid, IQueryable<Comment> AllComments, Player CurrentPlayer) { Comments = AllComments.GetComments(itemtype, itemid).Take(30).Select(c => new CommentSummary(c, CurrentPlayer)); ItemType = itemtype; ItemId = itemid; IsLoggedIn = (CurrentPlayer != null); TotalCommentCount = AllComments.GetComments(itemtype, itemid).Count(); }
public NotificationModelView(IQueryable<Comment> Comments, Notification notification, Player CurrentPlayer) { body = notification.Body; subject = notification.Subject; CreatedAndBy = "Posted by " + notification.Player.Name + " @ " + notification.Created.ToString("dd MMMM yyyy @ hh:mm tt"); //comments CommentModel = new CommentingViewModel(1, notification.Id, Comments, CurrentPlayer); }
public SeasonTablePlayerRow(Player player, IEnumerable<int> weekPoints, Season season) { PlayerDetail = new SimplePlayer(player); WeeksPoints = weekPoints.Select(w => w.ToString()); TotalPoints = weekPoints.Sum(w => w); Position = season.GetPlayerCurrentPosition(player); ChangeOfPosition = season.GetPlayerPositionChange(player); }
public SeasonTableModelView GetCurrentSeasonFromCache(IQueryable<Comment> comments, Player CurrentPlayer) { //get SeasonTableModelCaching var CurrentFromCache = GetSeasonTableModelCaching(); //build real SeasonTableModelView (none cached version includes up to date Comments) SeasonTableModelView Model = new SeasonTableModelView(comments, CurrentPlayer, CurrentFromCache.SeasonId); Model.ColumnNames = CurrentFromCache.ColumnNames; Model.Rows = CurrentFromCache.Rows; Model.SeasonEnd = CurrentFromCache.SeasonEnd; Model.SeasonStarts = CurrentFromCache.SeasonStarts; return Model; }
public SeasonTableModelView(Season season, IQueryable<Comment> Comments, Player CurrentPlayer) { SeasonEnd = season.SeasonEnd; SeasonStarts = season.SeasonStarts; //get active players Rows = season.GetActivePlayers().Select(p => new SeasonTablePlayerRow(p, season.GetPlayerPoints(p), season)) .OrderByDescending(x => x.TotalPoints).ToArray(); ColumnNames = season.Weeks.WeeksSoFar().Select(x => x.WeekStarts.ToString("dd MMM")).ToArray(); //comments CommentModel = new CommentingViewModel(8, season.Id, Comments, CurrentPlayer); }
public CommentSummary(Comment c, Player Player) { id = c.Id; body = c.Body.UserInputToHtml(); //Need to replace \n with br's?? postedBy = c.Player.Name; postedOn = "Posted " + c.Created.ToString("dd MMMM yyyy @ hh:mm tt"); LastEdited = "Edited " + c.Updated.ToString("dd MMMM yyyy @ hh:mm tt"); //currently any admin can edit/delete comments IsEdited = (Player != null) && ((c.Player.Id == Player.Id) || (Player.User.Role > 0)); //if updated after it was created if(c.Updated > c.Created){ PostedAndEditedText = string.Format("Edited {0} | Posted {1}", c.Updated.ToString("dd MMMM yyyy @ hh:mm tt"), c.Created.ToString("dd-MM-yy")); }else{ PostedAndEditedText = "Posted " + c.Created.ToString("dd MMMM yyyy @ hh:mm tt"); } }
public SeasonPlayerScoreCard(Player player, IEnumerable<PlayerPrediction> predictions) { Player = player; var weekPlayer = new List<WeekPlayerScoreCard>(); var weekPredictions = new List<PlayerPrediction>(); Week currentWeek = null; foreach (var prediction in predictions.OrderBy(x => x.Week.Id)) { if (prediction.Week.Id != currentWeek.Id) { weekPlayer.Add(new WeekPlayerScoreCard(currentWeek, weekPredictions)); } weekPredictions.Add(prediction); } WeekCards = weekPlayer; }
public ResultTableModelView(Season currentSeason, Player currentLoggedInPlayer, IEnumerable<Comment> Comments) { LoggedInPlayer = currentLoggedInPlayer; week = currentSeason.GetLastWeekSeason(); MatchOfTheWeek = week.MatchOfTheWeek; ThisWeeksMatches = week.AllMatches().OrderBy(m => m.MatchDate.Value); var LeaguePlayers = currentSeason.GetActivePlayers(); var PlayerPointsCollection = new Dictionary<SimplePlayer, List<int>>(); foreach (var p in LeaguePlayers) { var playerLastWeekPredictions = currentSeason.GetPlayersPredictionsForLastWeek(p); //For each Match this week get the players point List<int> Points = new List<int>(); foreach (var m in ThisWeeksMatches) { //if user has predictions then get them and add them (this way if player has 5predictions //and there was 8 matches we correctly fill in the 0 scoring matches var Prediction = playerLastWeekPredictions.Where(pp => pp.Match == m).SingleOrDefault(); if(Prediction != null){ Points.Add(Prediction.PointsEarned()); }else{ Points.Add(0); } } PlayerPointsCollection.Add(new SimplePlayer(p), Points); } PlayersPoints = PlayerPointsCollection; //comments CommentModel = new CommentingViewModel(7, week.Id, Comments.AsQueryable(), currentLoggedInPlayer); }
public virtual IEnumerable<PlayerPrediction> GetPlayersPredictionsForCurrentWeek(Player player) { var Week = GetWeekSeason(SystemDate.Current()); if (Week != null) { return Week.GetPlayersPredictions(player); } return null; }
public SeasonPlayerScoreCard(Player player, IEnumerable<WeekPlayerScoreCard> weekCards) { Player = player; WeekCards = weekCards; }
public static IEnumerable<int> GetPlayerPoints(this Season query, Player player) { return query.Weeks.WeeksSoFar().Select(w => query.GetTotalPointsForAPlayersWeek(player, w)).ToList(); }
public virtual int GetTotalPointsForAPlayerLastWeeks(Player player) { var pts = Weeks.WeeksUpTillLastweek().Select(w => GetTotalPointsForAPlayersWeek(player, w)).Sum(); return pts; }
public virtual IEnumerable<PlayerPrediction> GetPlayersPredictions(Player player) { return Predictions.Where(x => x.Player.Id == player.Id); }
protected virtual IEnumerable<PlayerPrediction> PlayersPredictions(Player player) { return Predictions.Where(x => x.Player.Id == player.Id); }
//used often for cache objects public SeasonTableModelView(IQueryable<Comment> Comments, Player CurrentPlayer, int SeasonId) { //comments CommentModel = new CommentingViewModel(8, SeasonId, Comments, CurrentPlayer); }
public User CreatePlayer(League playersleague) { //create users first var newUser = new User { Email = Email, Password = Password, Live = true, Created = SystemDate.Current(), Updated = SystemDate.Current(), ActivationCode = GetHashCode() }; //create the player next var newPlayer = new Player { Name = Username, User = newUser }; //add player to the league playersleague.Players.Add(newPlayer); return newUser; }
public virtual IEnumerable<PlayerPrediction> GetPlayersPredictionsForLastWeek(Player player) { var LastWeek = GetWeekSeason(SystemDate.Current().AddDays(-7)); if (LastWeek != null) { return GetWeekSeason(SystemDate.Current().AddDays(-7)).GetPlayersPredictions(player); } else { return null; } }
public virtual int GetTotalPointsForAPlayer(Player player) { return Weeks.WeeksSoFar().Select(w => GetTotalPointsForAPlayersWeek(player, w)).Sum(); }
public static int GetPlayerLastWeekPosition(this Season query, Player player) { var PlayersOrderedByPts = query.GetActivePlayers().OrderByDescending(p => query.GetTotalPointsForAPlayerLastWeeks(p)); return GetPlayerLastWeekPosition(query, PlayersOrderedByPts, player); }
public virtual int GetTotalPointsForAPlayersWeek(Player player, Week week) { return week.GetPlayerPredications().Where(pp => pp.Player.Id == player.Id).Sum(pp => pp.PointsEarned()); }
private PlayerPredictionsRow CreateRow(Player player, int MatchesCount) { var Predictions = player.GetPredictionsForThisWeek(); var PredictionsCount = Predictions.Count(); var ConfirmedPredictionsCount = Predictions.Where(p=> p.Confirmed == true).Count(); return new PlayerPredictionsRow { Player = player, Missing = MatchesCount - PredictionsCount, Confirmed = ConfirmedPredictionsCount, Unconfirmed = PredictionsCount - ConfirmedPredictionsCount }; }
private static string BuildPlayersLastWeekMatches(Season season, Player player) { var playerLastWeekPredictions = season.GetPlayersPredictionsForLastWeek(player); if (playerLastWeekPredictions == null) return ""; var summarysLastWeek = playerLastWeekPredictions.OrderBy(p => p.Match.MatchDate); if (summarysLastWeek.Count() > 0) { // build users result 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>Date</th>"); sb.Append("<th>Match</th>"); sb.Append("<th>My Prediction</th>"); sb.Append("<th>Result</th>"); sb.Append("<th style='text-align:right'>Pts</th>"); sb.Append("</tr>"); int i = 0; foreach(var prediction in summarysLastWeek){ var MatchName = string.Format("{0} vs {1}", prediction.Match.Boxers.First().FullName(), prediction.Match.Boxers.Last().FullName()); if (prediction.Match == prediction.Week.MatchOfTheWeek) { sb.Append("<tr style='background:#FFFCD6'>"); } else if (i % 2 == 0) { sb.Append("<tr style='background:#eeeeee'>"); } else { sb.Append("<tr>"); } sb.Append("<td>" + prediction.Match.MatchDate.Value.ordinalDateShortDay() + "</td>"); sb.Append("<td> " + MatchName + "</td>"); sb.Append("<td>" + prediction.ToTextSummary() + "</td>"); if (prediction.Match.HasResult()) { sb.Append("<td>" + prediction.Match.Result.ResultTextBPL() + "</td>"); } else { sb.Append("<td>N/A</td>"); } sb.Append("<td style='text-align:right'>" + prediction.PointsEarned() + "</td>"); sb.Append("</tr>"); i += 1; } sb.Append("<tfoot>"); sb.Append("<tr style='text-align:right'>"); sb.Append("<td colspan='4' >Last Weeks Total:</td>"); sb.Append("<td>" + summarysLastWeek.Sum(x => x.PointsEarned()) + "</td>"); sb.Append("</tr>"); sb.Append("</tfoot>"); sb.Append("</table>"); return sb.ToString(); } return ""; }
private IEnumerable<int> GetPlayerPoints(Player player, Season season) { return season.Weeks.Select(w => season.GetTotalPointsForAPlayersWeek(player, w)).ToList(); }