Esempio n. 1
0
        /// <summary>
        ///     Gets the featured users.
        /// </summary>
        /// <param name="boardSettings">The board settings.</param>
        /// <returns></returns>
        public List<CarouselData> GetFeaturedUsers(YafBoardSettings boardSettings)
        {
            var avatar = new YafAvatars(boardSettings); // not needed
            var userDs = Db.get_featured_profiles();

            var userFeaturedList = (from r in userDs.Tables[0].AsEnumerable()
                .Where(r => RapGlobalHelpers.IsDateExpired(r.Field<DateTime>("FeaturedUntil")) == false)
                select new CarouselData
                {
                    UserId = r.Field<int>("UserID"),
                    CaptionText = // not needed
                        String.Format("View {0}'s Profile",
                            UserMembershipHelper.GetDisplayNameFromID(r.Field<int>("UserID"))),// not needed
                    HyperLink = this.GetService<UrlProvider>().GetUrl("/Pages/Profile/{0}", (r.Field<int>("UserID"))),// not needed
                    ImagePath = avatar.GetAvatarUrlForUser(r.Field<int>("UserID")),
                    ExpiryDate = r.Field<DateTime>("FeaturedUntil") // not needed
                }).ToList();

            return userFeaturedList;
        }
Esempio n. 2
0
        /// <summary>
        ///     Gets the random users.
        /// </summary>
        /// <param name="boardSettings">The board settings.</param>
        /// <returns></returns>
        public List<CarouselData> GetRandomUsers(YafBoardSettings boardSettings)
        {
            var randomDs = Db.get_randomprofiles();
            var avatar = new YafAvatars(boardSettings);

            var randomProfileList =
                (from r in randomDs.Tables[0].AsEnumerable().Where(r => r.Field<int>("UserID") != 1)
                    select new CarouselData
                    {
                        UserId = r.Field<int>("UserID"),
                        CaptionText =
                            string.Format("View {0}'s profile",
                                UserMembershipHelper.GetDisplayNameFromID(r.Field<int>("UserID"))),
                        HyperLink =
                            this.GetService<UrlProvider>().GetUrl("/Pages/Profile/{0}", (r.Field<int>("UserID"))),
                        ImagePath = avatar.GetAvatarUrlForUser(r.Field<int>("UserID"))
                    }).Take(30).ToList();


            return randomProfileList;
        }
Esempio n. 3
0
        /// <summary>
        ///     Gets the users profile comments.
        /// </summary>
        /// <param name="boardSettings">The board settings.</param>
        /// <returns></returns>
        public List<UserComments> GetUsersProfileComments(YafBoardSettings boardSettings)
        {
            var commentsDs = Db.get_profilecomments(UserId);
            var avatar = new YafAvatars(boardSettings);

            var userComments =
                (from r in commentsDs.Tables[0].AsEnumerable()
                    select new UserComments
                    {
                        DisplayName = UserMembershipHelper.GetDisplayNameFromID(r.Field<int>("CommenterID")),
                        HyperLink =
                            this.GetService<UrlProvider>().GetUrl("/Pages/Profile/{0}", (r.Field<int>("CommenterID"))),
                        Avatar = avatar.GetAvatarUrlForUser(r.Field<int>("CommenterID")),
                        Comment = r.Field<string>("Comment"),
                        DatePosted = r.Field<DateTime>("DatePosted").ToString("MM/dd/yyyy")
                    }).ToList();

            return userComments;
        }
Esempio n. 4
0
        /// <summary>
        ///     Generates the results in HTML5
        /// </summary>
        /// <param name="tournament">The tournament.</param>
        /// <param name="url">The URL.</param>
        /// <returns></returns>
        public string GenerateResultsInHtml([NotNull] RapTournament tournament, [NotNull] string url)
        {
            Contract.Requires(tournament != null);
            var rounds = tournament.TournamentRoundMatches.Count;
            var battlers = 1 << rounds;
            var maxRows = battlers << 1;
            var htmlTable = new StringBuilder();
            const string avatarHtml = "<a href='/pages/profile/{0}'><img src='{1}' class='pull-left' alt='' height='25' width='25' />";
            htmlTable.AppendLine("<style type=\"text/css\">");
            htmlTable.AppendLine("    .thd {background: rgb(220,220,220); text-align: center;}");
            htmlTable.AppendLine(
                "    .team {background-color: #f5f5f5; font: bold 10pt Arial;}");
            htmlTable.AppendLine("    .winner {background-color: #f5f5f5;}");
            htmlTable.AppendLine("    .vs {font: bold 7pt Arial; vertical-align: middle !important;}");
            htmlTable.AppendLine(
                "    td, th {padding: 3px 15px; border-right: dotted 2px rgb(200,200,200); text-align: right;}");
            htmlTable.AppendLine("    h1 { margin-top: 24pt;}");
            htmlTable.AppendLine("</style>");

            htmlTable.AppendLine("<div class=\"bs-callout bs-callout-info\">");
            htmlTable.AppendLine("Tournament Results");
            htmlTable.AppendLine("</div>");
            htmlTable.AppendLine("<table id=\"tournamentTable\" class=\"table\" border=\"0\" cellspacing=\"0\">");
            for (var row = 0; row <= maxRows; row++)
            {
                var cumulativeMatches = 0;
                htmlTable.AppendLine("    <tr>");
                for (var col = 1; col <= rounds + 1; col++)
                {
                    var matchSpan = 1 << (col + 1);
                    var matchWhiteSpan = (1 << col) - 1;
                    var columnStaggerOffset = matchWhiteSpan >> 1;
                    switch (row)
                    {
                        case 0:
                            if (col <= rounds)
                            {
                                htmlTable.AppendLine("        <th class=\"thd\">Round " + col + "</th>");
                            }
                            else
                            {
                                htmlTable.AppendLine("        <th class=\"thd\">Winner</th>");
                            }
                            break;
                        case 1:
                            htmlTable.AppendLine("        <td class=\"white_span\" rowspan=\"" +
                                                 (matchWhiteSpan - columnStaggerOffset) + "\">&nbsp;</td>");
                            break;
                        default:
                        {
                            var effectiveRow = row + columnStaggerOffset;
                            if (col <= rounds)
                            {
                                var positionInMatchSpan = effectiveRow%matchSpan;
                                positionInMatchSpan = (positionInMatchSpan == 0) ? matchSpan : positionInMatchSpan;
                                var colMatchNum = (effectiveRow/matchSpan) + ((positionInMatchSpan < matchSpan) ? 1 : 0);
                                var effectiveMatchId = cumulativeMatches + colMatchNum;
                                if ((positionInMatchSpan == 1) && (effectiveRow%matchSpan == positionInMatchSpan))
                                {
                                    htmlTable.AppendLine("        <td class=\"white_span\" rowspan=\"" + matchWhiteSpan +
                                                         "\">&nbsp;</td>");
                                }
                                else if ((positionInMatchSpan == (matchSpan >> 1)) &&
                                         (effectiveRow%matchSpan == positionInMatchSpan))
                                {
                                    var userId = tournament.TournamentRoundMatches[col][effectiveMatchId].UserId1;
                                    var winnerId = tournament.TournamentRoundMatches[col][effectiveMatchId].WinnerId;
                                    if (userId != null)
                                    {
                                        var avatar =
                                            new YafAvatars(YafContext.Current.BoardSettings).GetAvatarUrlForUser((int)userId);
                                        if (winnerId == null)
                                        {
                                            htmlTable.AppendLine("        <td class=\"team\"> " + avatarHtml.FormatWith(userId, avatar) +
                                                                 UserMembershipHelper.GetDisplayNameFromID(
                                                                     (int)
                                                                         tournament.TournamentRoundMatches[col][
                                                                             effectiveMatchId]
                                                                             .UserId1) + "</td>");
                                        }
                                        else
                                        {
                                            if (winnerId == userId)
                                            {
                                                htmlTable.AppendLine("        <td class=\"team success\"> " + avatarHtml.FormatWith(userId, avatar) +
                                                                     UserMembershipHelper.GetDisplayNameFromID(
                                                                         (int)
                                                                             tournament.TournamentRoundMatches[col][
                                                                                 effectiveMatchId]
                                                                                 .UserId1) + "</td>");
                                            }
                                            else
                                            {
                                                htmlTable.AppendLine("        <td class=\"team danger\"> " + avatarHtml.FormatWith(userId, avatar) +
                                                                     UserMembershipHelper.GetDisplayNameFromID(
                                                                         (int)
                                                                             tournament.TournamentRoundMatches[col][
                                                                                 effectiveMatchId]
                                                                                 .UserId1) + "</td>");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        htmlTable.AppendLine("        <td class=\"team\"> " + "</td>");
                                    }
                                }
                                else if ((positionInMatchSpan == ((matchSpan >> 1) + 1)) &&
                                         (effectiveRow%matchSpan == positionInMatchSpan))
                                {
                                    var battleUrl = url +
                                                    tournament.TournamentRoundMatches[col][effectiveMatchId].BattleId;
                                    htmlTable.AppendLine("        <td class=\"vs\" rowspan=\"" + matchWhiteSpan +
                                                         "\"><a href='" + battleUrl + "'>VS</a></td>");
                                }
                                else if ((positionInMatchSpan == matchSpan) && (effectiveRow%matchSpan == 0))
                                {
                                    var userId = tournament.TournamentRoundMatches[col][effectiveMatchId].UserId2;
                                    var winnerId = tournament.TournamentRoundMatches[col][effectiveMatchId].WinnerId;
                                    if (userId != null)
                                    {
                                        var avatar =
                                            new YafAvatars(YafContext.Current.BoardSettings).GetAvatarUrlForUser(
                                                (int) userId);
                                        if (winnerId == null)
                                        {
                                            htmlTable.AppendLine("        <td class=\"team\"> " + avatarHtml.FormatWith(userId, avatar) +
                                                                 UserMembershipHelper.GetDisplayNameFromID(
                                                                     (int)
                                                                         tournament.TournamentRoundMatches[col][
                                                                             effectiveMatchId].UserId2)
                                                                 + "</td>");
                                        }
                                        else
                                        {
                                            if (winnerId == userId)
                                            {
                                                htmlTable.AppendLine("        <td class=\"team success\"> " + avatarHtml.FormatWith(userId, avatar) +
                                                                     UserMembershipHelper.GetDisplayNameFromID(
                                                                         (int)
                                                                             tournament.TournamentRoundMatches[col][
                                                                                 effectiveMatchId].UserId2)
                                                                     + "</td>");
                                            }
                                            else
                                            {
                                                htmlTable.AppendLine("        <td class=\"team danger\"> " + avatarHtml.FormatWith(userId, avatar) +
                                                                     UserMembershipHelper.GetDisplayNameFromID(
                                                                         (int)
                                                                             tournament.TournamentRoundMatches[col][
                                                                                 effectiveMatchId].UserId2)
                                                                     + "</td>");
                                            }
                                        }
                                    }
                                    else
                                    {
                                        htmlTable.AppendLine("        <td class=\"team\"> " + "</td>");
                                    }
                                }
                            }
                            else
                            {
                                if (row == columnStaggerOffset + 2)
                                {
                                    var winnerId = tournament.TournamentRoundMatches[rounds][cumulativeMatches].WinnerId;
                                    if (winnerId != null)
                                    {
                                        var avatar =
                                            new YafAvatars(YafContext.Current.BoardSettings).GetAvatarUrlForUser(
                                                (int)winnerId);
                                        if (tournament.TournamentStatus != RapTournamentStatus.Over)
                                        {
                                            tournament.TournamentStatus = RapTournamentStatus.Over;
                                            Db.update_tournamentstate(tournament.TournamentId,
                                                (int) tournament.TournamentStatus);
                                        }
                                        htmlTable.AppendLine("        <td class=\"winner warning\"> " + avatarHtml.FormatWith(winnerId, avatar) +
                                                             UserMembershipHelper.GetDisplayNameFromID(
                                                                 (int)
                                                                     tournament.TournamentRoundMatches[rounds][
                                                                         cumulativeMatches].WinnerId) + "</td>");
                                    }
                                    else
                                    {
                                        htmlTable.AppendLine("        <td class=\"winner\"> " + "</td>");
                                    }
                                }
                                else if (row == columnStaggerOffset + 3)
                                {
                                    htmlTable.AppendLine("        <td class=\"white_span\" rowspan=\"" +
                                                         (matchWhiteSpan - columnStaggerOffset) + "\">&nbsp;</td>");
                                }
                            }
                        }
                            break;
                    }
                    if (col <= rounds)
                    {
                        cumulativeMatches += tournament.TournamentRoundMatches[col].Count;
                    }
                }
                htmlTable.AppendLine("    </tr>");
            }
            htmlTable.AppendLine("</table>");
            if (tournament.ThirdPlaceMatch.UserId1 != null && tournament.ThirdPlaceMatch.UserId2 != null)
            {
                htmlTable.AppendLine("<div class=\"bs-callout bs-callout-info\">");
                htmlTable.AppendLine("Third Place Match");
                htmlTable.AppendLine("</div>");
                htmlTable.AppendLine("<table border=\"0\" class=\"table\" cellspacing=\"0\">");
                htmlTable.AppendLine("    <tr class=\"info\">");
                htmlTable.AppendLine("        <th class=\"thd\">Round 1</th>");
                htmlTable.AppendLine("        <th class=\"thd\">Third Place</th>");
                htmlTable.AppendLine("    </tr>");
                htmlTable.AppendLine("    <tr>");
                htmlTable.AppendLine("        <td class=\"white_span\">&nbsp;</td>");
                htmlTable.AppendLine("        <td class=\"white_span\" rowspan=\"2\">&nbsp;</td>");
                htmlTable.AppendLine("    </tr>");
                htmlTable.AppendLine("    <tr>");
                if (tournament.ThirdPlaceMatch.UserId1 != null)
                {
                    var avatar =
                        new YafAvatars(YafContext.Current.BoardSettings).GetAvatarUrlForUser(
                            (int)tournament.ThirdPlaceMatch.UserId1);
                    if (tournament.ThirdPlaceMatch.WinnerId == tournament.ThirdPlaceMatch.UserId1)
                    {
                        htmlTable.AppendLine("        <td class=\"team success\"> " + avatarHtml.FormatWith((int)tournament.ThirdPlaceMatch.UserId1, avatar) +
                                             UserMembershipHelper.GetDisplayNameFromID(
                                                 (int) tournament.ThirdPlaceMatch.UserId1) +
                                             "</td>");
                    }
                    else if (tournament.ThirdPlaceMatch.WinnerId != null)
                    {
                        htmlTable.AppendLine("        <td class=\"team danger\"> " + avatarHtml.FormatWith((int)tournament.ThirdPlaceMatch.UserId1, avatar) +
                                             UserMembershipHelper.GetDisplayNameFromID(
                                                 (int) tournament.ThirdPlaceMatch.UserId1) +
                                             "</td>");
                    }
                    else
                    {
                        htmlTable.AppendLine("        <td class=\"team\"> " + avatarHtml.FormatWith((int)tournament.ThirdPlaceMatch.UserId1, avatar) +
                                             UserMembershipHelper.GetDisplayNameFromID(
                                                 (int) tournament.ThirdPlaceMatch.UserId1) +
                                             "</td>");
                    }
                }
                else
                {
                    htmlTable.AppendLine("        <td class=\"team\"> " + "</td>");
                }
                htmlTable.AppendLine("    </tr>");
                htmlTable.AppendLine("    <tr>");
                htmlTable.AppendLine("        <td class=\"vs\"><a href='" + url + tournament.ThirdPlaceMatch.BattleId + "'>VS</a></td>");
                if (tournament.ThirdPlaceMatch.WinnerId != null)
                {
                    var avatar =
                        new YafAvatars(YafContext.Current.BoardSettings).GetAvatarUrlForUser(
                            (int)tournament.ThirdPlaceMatch.WinnerId);
                    htmlTable.AppendLine("        <td class=\"winner warning\"> " + avatarHtml.FormatWith((int)tournament.ThirdPlaceMatch.WinnerId, avatar) +
                                         UserMembershipHelper.GetDisplayNameFromID(
                                             (int) tournament.ThirdPlaceMatch.WinnerId) +
                                         "</td>");
                }
                else
                {
                    htmlTable.AppendLine("        <td class=\"winner\"> " + "</td>");
                }
                htmlTable.AppendLine("    </tr>");
                htmlTable.AppendLine("    <tr>");
                if (tournament.ThirdPlaceMatch.UserId2 != null)
                {
                    var avatar =
                        new YafAvatars(YafContext.Current.BoardSettings).GetAvatarUrlForUser(
                            (int)tournament.ThirdPlaceMatch.UserId2);
                    if (tournament.ThirdPlaceMatch.WinnerId == tournament.ThirdPlaceMatch.UserId2)
                    {
                        htmlTable.AppendLine("        <td class=\"team success\"> " + avatarHtml.FormatWith((int)tournament.ThirdPlaceMatch.UserId2, avatar) +
                                             UserMembershipHelper.GetDisplayNameFromID(
                                                 (int) tournament.ThirdPlaceMatch.UserId2) +
                                             "</td>");
                    }
                    else if (tournament.ThirdPlaceMatch.WinnerId != null)
                    {
                        htmlTable.AppendLine("        <td class=\"team danger\"> " + avatarHtml.FormatWith((int)tournament.ThirdPlaceMatch.UserId2, avatar) +
                                             UserMembershipHelper.GetDisplayNameFromID(
                                                 (int) tournament.ThirdPlaceMatch.UserId2) +
                                             "</td>");
                    }
                    else
                    {
                        htmlTable.AppendLine("        <td class=\"team\"> " + avatarHtml.FormatWith((int)tournament.ThirdPlaceMatch.UserId2, avatar) +
                                             UserMembershipHelper.GetDisplayNameFromID(
                                                 (int) tournament.ThirdPlaceMatch.UserId2) +
                                             "</td>");
                    }
                }
                else
                {
                    htmlTable.AppendLine("        <td class=\"team\"> " + "</td>");
                }
                htmlTable.AppendLine("        <td class=\"white_span\">&nbsp;</td>");
                htmlTable.AppendLine("    </tr>");
                htmlTable.AppendLine("</table>");
            }
            return htmlTable.ToString();
        }