コード例 #1
0
        /// <summary>
        /// Return an object containing information about the badge, typically for when badge
        /// details are to be displayed.
        /// </summary>
        /// <param name="server">An <see cref="HttpServerUtility"/> for context information</param>
        /// <param name="badgeId">The ID number of the badge</param>
        /// <param name="patronId">The ID number of the patron - 0 or below if we don't know the
        /// patron's ID</param>
        /// <returns>A populated <see cref="BadgeDisplayDetails"/> with badge details</returns>
        public BadgeDisplayDetails GetForDisplay(HttpServerUtility server,
                                                 int badgeId,
                                                 int patronId)
        {
            var badge = SRP.DAL.Badge.FetchObject(badgeId);

            if (badge == null)
            {
                throw new Exception("Badge not found.");
            }
            var badgeDetails = new BadgeDisplayDetails();

            badgeDetails.BadgeId                = badge.BID;
            badgeDetails.DisplayName            = badge.UserName;
            badgeDetails.HideDefaultDescription = badge.HideDefaultDescriptionFlag;
            badgeDetails.Description            = badge.CustomDescription;
            badgeDetails.Hidden = badge.HiddenFromPublic == true;

            // if the badge is flagged as hidden from the public, ensure the user has earned it
            if (patronId > 0)
            {
                var patronBadges = SRP.DAL.PatronBadges.GetAll(patronId);
                if (patronBadges != null && patronBadges.Tables.Count > 0)
                {
                    var filterExpression = string.Format("BadgeID = {0}", badge.BID);
                    var patronHasBadge   = patronBadges.Tables[0].Select(filterExpression);
                    if (patronHasBadge.Count() > 0)
                    {
                        badgeDetails.Earned = true;
                        var earned = patronHasBadge[0]["DateEarned"] as DateTime?;
                        if (earned != null)
                        {
                            badgeDetails.DateEarned = ((DateTime)earned).ToShortDateString();
                        }
                    }
                }
            }

            string badgePath          = NoBadgePath;
            string potentialBadgePath = string.Format("~/Images/Badges/{0}.png",
                                                      badgeId);

            if (System.IO.File.Exists(server.MapPath(potentialBadgePath)))
            {
                badgePath = potentialBadgePath;
            }
            badgeDetails.ImageUrl      = badgePath;
            badgeDetails.AlternateText = string.Format("Badge: {0}", badge.UserName);


            var earn = new HashSet <string>();

            string earnText = SRP.DAL.Badge.GetBadgeReading(badgeId);

            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Earn points by reading: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeGoal(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Achieve part of your personal reading goal: {0}.",
                                       earnText));
            }

            earnText = SRP.DAL.Badge.GetEnrollmentPrograms(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Enroll in a reading program: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeBookLists(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Complete a Challenge: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeGames(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Unlock and complete an Adventure: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeEvents(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Attend an Event: {0}.",
                                       CreateSearchLinks(server, earnText, "~/Events/?Search={0}")));
            }

            if (earn.Count == 0)
            {
                earn.Add("Learn the secret code to unlock it.");
            }

            badgeDetails.HowToEarn = earn.OrderBy(x => x).ToArray();

            return(badgeDetails);
        }
コード例 #2
0
        /// <summary>
        /// Return an object containing information about the badge, typically for when badge
        /// details are to be displayed.
        /// </summary>
        /// <param name="server">An <see cref="HttpServerUtility"/> for context information</param>
        /// <param name="badgeId">The ID number of the badge</param>
        /// <param name="patronId">The ID number of the patron - 0 or below if we don't know the
        /// patron's ID</param>
        /// <returns>A populated <see cref="BadgeDisplayDetails"/> with badge details</returns>
        public BadgeDisplayDetails GetForDisplay(HttpServerUtility server,
            int badgeId,
            int patronId)
        {
            var badge = SRP.DAL.Badge.FetchObject(badgeId);
            if (badge == null)
            {
                throw new Exception("Badge not found.");
            }
            var badgeDetails = new BadgeDisplayDetails();

            badgeDetails.BadgeId = badge.BID;
            badgeDetails.DisplayName = badge.UserName;
            badgeDetails.HideDefaultDescription = badge.HideDefaultDescriptionFlag;
            badgeDetails.Description = badge.CustomDescription;
            badgeDetails.Hidden = badge.HiddenFromPublic == true;

            // if the badge is flagged as hidden from the public, ensure the user has earned it
            if (patronId > 0)
            {
                var patronBadges = SRP.DAL.PatronBadges.GetAll(patronId);
                if (patronBadges != null && patronBadges.Tables.Count > 0)
                {
                    var filterExpression = string.Format("BadgeID = {0}", badge.BID);
                    var patronHasBadge = patronBadges.Tables[0].Select(filterExpression);
                    if (patronHasBadge.Count() > 0)
                    {
                        badgeDetails.Earned = true;
                        var earned = patronHasBadge[0]["DateEarned"] as DateTime?;
                        if (earned != null)
                        {
                            badgeDetails.DateEarned = ((DateTime)earned).ToShortDateString();
                        }
                    }
                }
            }

            string badgePath = NoBadgePath;
            string potentialBadgePath = string.Format("~/Images/Badges/{0}.png",
                                                      badgeId);
            if (System.IO.File.Exists(server.MapPath(potentialBadgePath)))
            {
                badgePath = potentialBadgePath;
            }
            badgeDetails.ImageUrl = badgePath;
            badgeDetails.AlternateText = string.Format("Badge: {0}", badge.UserName);


            var earn = new HashSet<string>();

            string earnText = SRP.DAL.Badge.GetBadgeReading(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Earn points by reading: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeGoal(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Achieve part of your personal reading goal: {0}.",
                    earnText));
            }

            earnText = SRP.DAL.Badge.GetEnrollmentPrograms(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Enroll in a reading program: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeBookLists(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Complete a Challenge: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeGames(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Unlock and complete an Adventure: {0}.", earnText));
            }

            earnText = SRP.DAL.Badge.GetBadgeEvents(badgeId);
            if (earnText.Length > 0)
            {
                earn.Add(string.Format("Attend an Event: {0}.",
                    CreateSearchLinks(server, earnText, "~/Events/?Search={0}")));
            }

            if (earn.Count == 0)
            {
                earn.Add("Learn the secret code to unlock it.");
            }

            badgeDetails.HowToEarn = earn.OrderBy(x => x).ToArray();

            return badgeDetails;
        }