Пример #1
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;
        }
Пример #2
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;
        }
Пример #3
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);
        }
Пример #4
0
 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);
 }
Пример #5
0
        public SeasonTableModelCaching(Season season)
        {
            SeasonEnd = season.SeasonEnd;
             SeasonStarts = season.SeasonStarts;
             SeasonId = season.Id;

             //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();
        }
Пример #6
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);
        }
Пример #7
0
        public static Season CreateSeason(DateTime current, League league)
        {
            var weeks = new List<Week>(10);
            for (int i = 0; i < 10; i++)
            {
                DateTime weekStart = current.AddDays(7 * i);
                var week = CreateWeek(weekStart);
                weeks.Add(week);
            }

            var newSeason = new Season(weeks, league);

            league.Seasons.Add(newSeason);

            return newSeason;
        }
Пример #8
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);
        }
Пример #9
0
 public virtual int CurrentTotalPoints(Season season)
 {
     return season.GetPlayerPoints(this).Sum();
 }
Пример #10
0
        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 "";
        }
Пример #11
0
        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();
        }
Пример #12
0
        public static int SendPredictionsReminderEmail(Season season)
        {
            var StartTime = DateTime.Now;

            var thisWeek = season.GetCurrentWeekSeason();
            int EmailCount = 0;

            var PlayersNoPredictions = season.League.Players.Where(x => !x.HasCompletedPredictions(thisWeek)).ToList();

            //TODO: this will probably crash at the end/start of a season!
            foreach (var player in PlayersNoPredictions)
            {
                //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>This is a last minute warning that you have yet to enter some or all of your predictions for this week.</p>");
                body.Append(string.Format("<h2>Get your predictions in today by <span style='color:red'>{0}</span>.</h2>", thisWeek.WeekCutOff.ToString("HH:mm")));
                body.Append("<h2>To add your predictions <a href='http://www.britboxing.co.uk/boxingpredictionleague/addprediction'>Click Here</a></h2>");
                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, "*****@*****.**", "Final Reminder - Get your predictions in"))
                    {
                        EmailCount += 1;
                    }
                }
            }

            BuildAndSendAdminEmail("Friday Reminder", EmailCount, StartTime, DateTime.Now);
            return EmailCount;
        }
Пример #13
0
        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;
        }
 public AllPlayerPredictionsModelView(Season _Season)
 {
     LeagueName = _Season.League.Name;
     Players = _Season.League.Players;
     Weeks = _Season.Weeks.WeeksSoFarIncludingThisWeek();
 }
Пример #15
0
 private IEnumerable<int> GetPlayerPoints(Player player, Season season)
 {
     return season.Weeks.Select(w => season.GetTotalPointsForAPlayersWeek(player, w)).ToList();
 }