Пример #1
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);
        }
Пример #2
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 "";
        }