Пример #1
0
        public static string Score(this HtmlHelper helper, string score, ScoreSize scoreSize, int?scoreCount, int?reviewedCount, int?favedCount, int?visitedCount)
        {
            // Create tag builder
            var builder     = new TagBuilder("span");
            int reviewedCnt = reviewedCount ?? 0;
            int favedCnt    = favedCount ?? 0;
            int visitedCnt  = visitedCount ?? 0;

            string qt = (reviewedCnt > 0) ? "qt " : string.Empty;

            string className     = qt + "rating-score-sm ";
            string className2    = qt + "rating-word ";
            string className3    = string.Empty;
            string ratingWord    = string.Empty;
            string scoreWord     = string.Empty;
            string ratingHtml    = string.Empty;
            string ratingMessage = string.Empty;

            if (scoreSize == ScoreSize.Large)
            {
                className = "qt rating-score ";
            }

            if (string.IsNullOrEmpty(score) || score == "0")
            {
                ratingMessage = "<span class=\"rating-msg\">Login to rate</span>";
                className     = string.Concat(className, "unrated");
                className2    = string.Concat(className2, "unrated");
                ratingWord    = "Unrated";
                scoreWord     = "?";
            }
            else
            {
                if (scoreCount != null)
                {
                    ratingMessage = string.Format("<span class=\"rating-msg\">Based on {0} rating{1}</span>", scoreCount, ((scoreCount == 1) ? string.Empty : "s"));
                }
                else
                {
                    ratingMessage = string.Empty;
                }
                scoreWord = score;
                int s = Convert.ToInt32(score);
                if (s < 30)
                {
                    className = string.Concat(className, "bottom");
                }
                else if (s > 69)
                {
                    className = string.Concat(className, "top");
                }
                else
                {
                    className = string.Concat(className, "middle");
                }

                if (s == 100)
                {
                    className  = string.Concat(className, " max");
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Perfect";
                }
                if (s < 100)
                {
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Superb";
                }
                if (s < 90)
                {
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Fantastic";
                }
                if (s < 80)
                {
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Great";
                }
                if (s < 70)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "Really Good";
                }
                if (s < 60)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "Good";
                }
                if (s < 50)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "OK";
                }
                if (s < 40)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "Below Average";
                }
                if (s < 30)
                {
                    className3 = string.Concat(className2, "bottom");
                    ratingWord = "Really Bad";
                }
                if (s < 20)
                {
                    className3 = string.Concat(className2, "bottom");
                    ratingWord = "Awful";
                }
                if (s < 10)
                {
                    className3 = string.Concat(className2, "bottom");
                    ratingWord = "Terrible";
                }
            }

            if (scoreSize == ScoreSize.Large)
            {
//                ratingHtml = "<p class=\"rating-word-wrap\"><span class=\"" + className2 + "\">" + ratingWord + "</span>" + ratingMessage + "</p>";

                ratingHtml  = "<table class=\"community-stats\">";
                ratingHtml += "<tr class=\"qt\" title=\"Reviewed\">";
                ratingHtml += "<td class=\"" + ((reviewedCnt == 0) ? "g" : "b") + " w24\"><img src=\"/Static/Images/white-star_48.png\" /></td>";
                ratingHtml += "<td class=\"" + ((reviewedCnt == 0) ? "g" : "b") + "\"><span class=\"counter\">" + reviewedCnt + "</span></td>";
                ratingHtml += "</tr>";
                ratingHtml += "</table>";
                ratingHtml += "<table class=\"community-stats\">";
                ratingHtml += "<tr class=\"qt\" title=\"Visited\">";
                ratingHtml += "<td class=\"" + ((visitedCnt == 0) ? "g" : "b") + " w24\"><img src=\"/Static/Images/white-tick_48.png\" /></td>";
                ratingHtml += "<td class=\"" + ((visitedCnt == 0) ? "g" : "b") + "\"><span class=\"counter\">" + visitedCnt + "</span></td>";
                ratingHtml += "</tr>";
                ratingHtml += "</table>";
                ratingHtml += "<table class=\"community-stats\">";
                ratingHtml += "<tr class=\"qt\" title=\"Faved\">";
                ratingHtml += "<td class=\"" + ((favedCnt == 0) ? "g" : "b") + " w24\"><img src=\"/Static/Images/white-heart_48.png\" /></td>";
                ratingHtml += "<td class=\"" + ((favedCnt == 0) ? "g" : "b") + "\"><span class=\"counter\">" + favedCnt + "</span></td>";
                ratingHtml += "</tr>";
                ratingHtml += "</table>";
            }

            // Add attributes
            //if (scoreSize == ScoreSize.Large)
            //{
            //    builder.InnerHtml = ratingWord;
            //}
            //else
            //{
            //}

            if (scoreSize == ScoreSize.Large)
            {
                scoreWord += "<span class=\"rating-score-total\">out of 100</span>";
            }
            builder.InnerHtml = scoreWord;
            if (reviewedCnt > 0)
            {
                builder.Attributes.Add("title", string.Format("Based on {0} review{1}", reviewedCnt, (reviewedCnt == 1) ? string.Empty : "s"));
            }
            builder.MergeAttribute("class", className);

            // Render tag
            //return builder.ToString(TagRenderMode.SelfClosing);
            return(builder.ToString() + ratingHtml);
        }
Пример #2
0
        public static string Score(this HtmlHelper helper, string score, ScoreSize scoreSize, int? scoreCount, int? reviewedCount, int? favedCount, int? visitedCount)
        {
            // Create tag builder
            var builder = new TagBuilder("span");
            int reviewedCnt = reviewedCount ?? 0;
            int favedCnt = favedCount ?? 0;
            int visitedCnt = visitedCount ?? 0;

            string qt = (reviewedCnt > 0) ? "qt " : string.Empty;

            string className = qt + "rating-score-sm ";
            string className2 = qt + "rating-word ";
            string className3 = string.Empty;
            string ratingWord = string.Empty;
            string scoreWord = string.Empty;
            string ratingHtml = string.Empty;
            string ratingMessage = string.Empty;

            if (scoreSize == ScoreSize.Large)
            {
                className = "qt rating-score ";
            }

            if (string.IsNullOrEmpty(score) || score == "0")
            {
                ratingMessage = "<span class=\"rating-msg\">Login to rate</span>";
                className = string.Concat(className, "unrated");
                className2 = string.Concat(className2, "unrated");
                ratingWord = "Unrated";
                scoreWord = "?";
            }
            else
            {
                if (scoreCount != null)
                {
                    ratingMessage = string.Format("<span class=\"rating-msg\">Based on {0} rating{1}</span>", scoreCount, ((scoreCount == 1) ? string.Empty : "s"));
                }
                else
                {
                    ratingMessage = string.Empty;
                }
                scoreWord = score;
                int s = Convert.ToInt32(score);
                if (s < 30)
                {
                    className = string.Concat(className, "bottom");
                }
                else if (s > 69)
                {
                    className = string.Concat(className, "top");
                }
                else
                {
                    className = string.Concat(className, "middle");
                }

                if (s == 100)
                {
                    className = string.Concat(className, " max");
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Perfect";
                }
                if (s < 100)
                {
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Superb";
                }
                if (s < 90)
                {
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Fantastic";
                }
                if (s < 80)
                {
                    className3 = string.Concat(className2, "top");
                    ratingWord = "Great";
                }
                if (s < 70)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "Really Good";
                }
                if (s < 60)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "Good";
                }
                if (s < 50)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "OK";
                }
                if (s < 40)
                {
                    className3 = string.Concat(className2, "middle");
                    ratingWord = "Below Average";
                }
                if (s < 30)
                {
                    className3 = string.Concat(className2, "bottom");
                    ratingWord = "Really Bad";
                }
                if (s < 20)
                {
                    className3 = string.Concat(className2, "bottom");
                    ratingWord = "Awful";
                }
                if (s < 10)
                {
                    className3 = string.Concat(className2, "bottom");
                    ratingWord = "Terrible";
                }
            }

            if (scoreSize == ScoreSize.Large)
            {
            //                ratingHtml = "<p class=\"rating-word-wrap\"><span class=\"" + className2 + "\">" + ratingWord + "</span>" + ratingMessage + "</p>";

                ratingHtml = "<table class=\"community-stats\">";
                ratingHtml += "<tr class=\"qt\" title=\"Reviewed\">";
                ratingHtml += "<td class=\"" + ((reviewedCnt == 0) ? "g" : "b") + " w24\"><img src=\"/Static/Images/white-star_48.png\" /></td>";
                ratingHtml += "<td class=\"" + ((reviewedCnt == 0) ? "g" : "b") + "\"><span class=\"counter\">" + reviewedCnt + "</span></td>";
                ratingHtml += "</tr>";
                ratingHtml += "</table>";
                ratingHtml += "<table class=\"community-stats\">";
                ratingHtml += "<tr class=\"qt\" title=\"Visited\">";
                ratingHtml += "<td class=\"" + ((visitedCnt == 0) ? "g" : "b") + " w24\"><img src=\"/Static/Images/white-tick_48.png\" /></td>";
                ratingHtml += "<td class=\"" + ((visitedCnt == 0) ? "g" : "b") + "\"><span class=\"counter\">" + visitedCnt + "</span></td>";
                ratingHtml += "</tr>";
                ratingHtml += "</table>";
                ratingHtml += "<table class=\"community-stats\">";
                ratingHtml += "<tr class=\"qt\" title=\"Faved\">";
                ratingHtml += "<td class=\"" + ((favedCnt == 0) ? "g" : "b") + " w24\"><img src=\"/Static/Images/white-heart_48.png\" /></td>";
                ratingHtml += "<td class=\"" + ((favedCnt == 0) ? "g" : "b") + "\"><span class=\"counter\">" + favedCnt + "</span></td>";
                ratingHtml += "</tr>";
                ratingHtml += "</table>";
            }

            // Add attributes
            //if (scoreSize == ScoreSize.Large)
            //{
            //    builder.InnerHtml = ratingWord;
            //}
            //else
            //{
            //}

            if (scoreSize == ScoreSize.Large)
            {
                scoreWord += "<span class=\"rating-score-total\">out of 100</span>";
            }
            builder.InnerHtml = scoreWord;
            if (reviewedCnt > 0)
                builder.Attributes.Add("title", string.Format("Based on {0} review{1}", reviewedCnt, (reviewedCnt == 1) ? string.Empty : "s"));
            builder.MergeAttribute("class", className);

            // Render tag
            //return builder.ToString(TagRenderMode.SelfClosing);
            return builder.ToString() + ratingHtml;
        }