コード例 #1
0
        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;
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: PlayerPrediction.cs プロジェクト: elmo61/BritBoxing
 public PlayerPrediction(Player player, Match match, DateTime createdOn)
     : this()
 {
     Player = player;
     Match = match;
     CreatedOn = createdOn;
 }
コード例 #4
0
 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;
 }
コード例 #5
0
        //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;
        }
コード例 #6
0
ファイル: HelpfulModels.cs プロジェクト: elmo61/BritBoxing
        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";
            }
        }
コード例 #7
0
        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;
        }
コード例 #8
0
 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();
 }
コード例 #9
0
 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);
 }
コード例 #10
0
ファイル: HelpfulModels.cs プロジェクト: elmo61/BritBoxing
 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);
 }
コード例 #11
0
ファイル: Caching.cs プロジェクト: elmo61/BritBoxing
        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;
        }
コード例 #12
0
        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);
        }
コード例 #13
0
        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");
            }
        }
コード例 #14
0
ファイル: PlayerScoreCard.cs プロジェクト: elmo61/BritBoxing
        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;
        }
コード例 #15
0
        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);
        }
コード例 #16
0
ファイル: Season.cs プロジェクト: elmo61/BritBoxing
 public virtual IEnumerable<PlayerPrediction> GetPlayersPredictionsForCurrentWeek(Player player)
 {
     var Week = GetWeekSeason(SystemDate.Current());
     if (Week != null)
     {
         return Week.GetPlayersPredictions(player);
     }
     return null;
 }
コード例 #17
0
ファイル: PlayerScoreCard.cs プロジェクト: elmo61/BritBoxing
 public SeasonPlayerScoreCard(Player player, IEnumerable<WeekPlayerScoreCard> weekCards)
 {
     Player = player;
     WeekCards = weekCards;
 }
コード例 #18
0
 public static IEnumerable<int> GetPlayerPoints(this Season query, Player player)
 {
     return query.Weeks.WeeksSoFar().Select(w => query.GetTotalPointsForAPlayersWeek(player, w)).ToList();
 }
コード例 #19
0
ファイル: Season.cs プロジェクト: elmo61/BritBoxing
 public virtual int GetTotalPointsForAPlayerLastWeeks(Player player)
 {
     var pts =  Weeks.WeeksUpTillLastweek().Select(w => GetTotalPointsForAPlayersWeek(player, w)).Sum();
     return pts;
 }
コード例 #20
0
ファイル: Week.cs プロジェクト: elmo61/BritBoxing
 public virtual IEnumerable<PlayerPrediction> GetPlayersPredictions(Player player)
 {
     return Predictions.Where(x => x.Player.Id == player.Id);
 }
コード例 #21
0
ファイル: Season.cs プロジェクト: elmo61/BritBoxing
 protected virtual IEnumerable<PlayerPrediction> PlayersPredictions(Player player)
 {
     return Predictions.Where(x => x.Player.Id == player.Id);
 }
コード例 #22
0
 //used often for cache objects
 public SeasonTableModelView(IQueryable<Comment> Comments, Player CurrentPlayer, int SeasonId)
 {
     //comments
     CommentModel = new CommentingViewModel(8, SeasonId, Comments, CurrentPlayer);
 }
コード例 #23
0
ファイル: HelperClasses.cs プロジェクト: elmo61/BritBoxing
        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;
        }
コード例 #24
0
ファイル: Season.cs プロジェクト: elmo61/BritBoxing
 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;
     }
 }
コード例 #25
0
ファイル: Season.cs プロジェクト: elmo61/BritBoxing
 public virtual int GetTotalPointsForAPlayer(Player player)
 {
     return Weeks.WeeksSoFar().Select(w => GetTotalPointsForAPlayersWeek(player, w)).Sum();
 }
コード例 #26
0
 public static int GetPlayerLastWeekPosition(this Season query, Player player)
 {
     var PlayersOrderedByPts = query.GetActivePlayers().OrderByDescending(p => query.GetTotalPointsForAPlayerLastWeeks(p));
     return GetPlayerLastWeekPosition(query, PlayersOrderedByPts, player);
 }
コード例 #27
0
ファイル: Season.cs プロジェクト: elmo61/BritBoxing
 public virtual int GetTotalPointsForAPlayersWeek(Player player, Week week)
 {
     return week.GetPlayerPredications().Where(pp => pp.Player.Id == player.Id).Sum(pp => pp.PointsEarned());
 }
コード例 #28
0
ファイル: StatsModelView.cs プロジェクト: elmo61/BritBoxing
        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
            };
        }
コード例 #29
0
ファイル: EmailBuilder.cs プロジェクト: elmo61/BritBoxing
        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 "";
        }
コード例 #30
0
 private IEnumerable<int> GetPlayerPoints(Player player, Season season)
 {
     return season.Weeks.Select(w => season.GetTotalPointsForAPlayersWeek(player, w)).ToList();
 }