コード例 #1
0
        protected void LookupChallenge(int blid)
        {
            var bl = BookList.FetchObject(blid);

            if (bl == null)
            {
                challengeDetails.Visible = false;
                new SessionTools(Session).AlertPatron("Could not find details on that Challenge.",
                                                      PatronMessageLevels.Warning,
                                                      "exclamation-sign");
            }
            else
            {
                challengeTitle.Text = bl.ListName;
                this.Title          = string.Format("{0} Challenge", challengeTitle.Text);
                lblDesc.Text        = Server.HtmlDecode(bl.Description);

                string award = null;

                if (bl.AwardPoints > 0)
                {
                    award = string.Format("Completing this challenge will earn: <strong>{0} point{1}</strong>",
                                          bl.AwardPoints,
                                          bl.AwardPoints > 1 ? "s" : string.Empty);
                }

                if (bl.AwardBadgeID > 0)
                {
                    if (string.IsNullOrWhiteSpace(award))
                    {
                        award = "Completing this challenge will earn: <strong>a badge</strong>.";
                    }
                    else
                    {
                        award += " and <strong>a badge</strong>.";
                    }

                    BadgeImage.Text = string.Format("<img class=\"thumbnail disabled\" src=\"/images/badges/sm_{0}.png\" />", bl.AwardBadgeID);
                }
                else
                {
                    BadgeImage.Text = string.Empty;
                    award          += ".";
                }

                BadgeImage.Visible = !string.IsNullOrEmpty(BadgeImage.Text);

                if (!string.IsNullOrWhiteSpace(award))
                {
                    lblPoints.Text    = award;
                    lblPoints.Visible = true;
                }
                var ds = BookListBooks.GetForDisplay(bl.BLID, ((Patron)Session["Patron"]).PID);
                rptr.DataSource = ds;
                rptr.DataBind();

                this.ShowModal = true;
            }
        }
コード例 #2
0
        protected void rptr_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var BLID = int.Parse(e.CommandArgument.ToString());

            var bl = BookList.FetchObject(BLID);

            lblTitle.Text = bl.ListName;
            lblDesc.Text  = Server.HtmlDecode(bl.Description);

            string award = null;

            if (bl.AwardPoints > 0)
            {
                award = string.Format("Completing this challenge will earn: <strong>{0} point{1}</strong>",
                                      bl.AwardPoints,
                                      bl.AwardPoints > 1 ? "s" : string.Empty);
            }

            if (bl.AwardBadgeID > 0)
            {
                if (string.IsNullOrWhiteSpace(award))
                {
                    award = "Completing this challenge will earn: <strong>a badge</strong>.";
                }
                else
                {
                    award += " and <strong>a badge</strong>.";
                }

                BadgeImage.Text = string.Format("<img class=\"thumbnail disabled\" src=\"/images/badges/sm_{0}.png\" />", bl.AwardBadgeID);
            }
            else
            {
                BadgeImage.Text = string.Empty;
                award          += ".";
            }

            BadgeImage.Visible = !string.IsNullOrEmpty(BadgeImage.Text);

            if (!string.IsNullOrWhiteSpace(award))
            {
                lblPoints.Text    = award;
                lblPoints.Visible = true;
            }

            lblTitle.Visible = true;
            lblDesc.Visible  = true;

            var ds = BookListBooks.GetForDisplay(bl.BLID, ((Patron)Session["Patron"]).PID);

            rptr2.DataSource = ds;
            rptr2.DataBind();
            printLink.NavigateUrl = string.Format("~/Challenges/Details.aspx?blid={0}&print=1",
                                                  bl.BLID);
            pnlDetail.Visible = true;
            this.ShowModal    = true;
        }
コード例 #3
0
        protected void rptr_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var BLID = int.Parse(e.CommandArgument.ToString());

            var bl = BookList.FetchObject(BLID);

            lblTitle.Text = bl.ListName;
            lblDesc.Text  = bl.Description;

            lblTitle.Visible = true;
            lblDesc.Visible  = true;

            var ds = BookListBooks.GetForDisplay(bl.BLID, ((Patron)Session["Patron"]).PID);

            rptr2.DataSource = ds;
            rptr2.DataBind();

            pnlDetail.Visible  = true;
            btnSave.Visible    = btnPrint.Visible = true;
            lblMessage.Visible = false;
        }
コード例 #4
0
        protected void LookupChallenge(int blid)
        {
            var bl = BookList.FetchObject(blid);

            if (bl == null)
            {
                challengeDetails.Visible = false;
                new SessionTools(Session).AlertPatron("Could not find details on that Challenge.",
                                                      PatronMessageLevels.Warning,
                                                      "exclamation-sign");
            }
            else
            {
                int patronId = -1;
                var p        = Session[SessionKey.Patron] as Patron;
                if (p != null)
                {
                    patronId = p.PID;
                }

                // see if this is bound to a specific program
                if (bl.ProgID != 0)
                {
                    // no user is logged in, don't show it
                    if (p == null)
                    {
                        var prog = DAL.Programs.FetchObject(bl.ProgID);
                        challengeDetails.Visible = false;
                        new SessionTools(Session).AlertPatron(
                            string.Format("You must be registered in the <strong>{0}</strong> program to view this Challenge.",
                                          prog.TabName),
                            PatronMessageLevels.Warning,
                            "exclamation-sign");
                    }

                    // user is registered under another program
                    if (p != null && bl.ProgID != p.ProgID)
                    {
                        var prog = DAL.Programs.FetchObject(bl.ProgID);
                        challengeDetails.Visible = false;
                        new SessionTools(Session).AlertPatron(
                            string.Format("That Challenge is only available to people in the <strong>{0}</strong> program.",
                                          prog.TabName),
                            PatronMessageLevels.Warning,
                            "exclamation-sign");
                    }
                }

                if (challengeDetails.Visible)
                {
                    Badge badge = null;

                    challengeTitle.Text = bl.ListName;
                    this.Title          = string.Format("Challenge: {0}", challengeTitle.Text);
                    lblDesc.Text        = string.Format("<p>{0}</p>", Server.HtmlDecode(bl.Description));

                    string award = null;

                    if (bl.AwardPoints > 0)
                    {
                        award = string.Format("Completing <strong>{0} task{1}</strong> will earn: <strong>{2} point{3}</strong>",
                                              bl.NumBooksToComplete,
                                              bl.NumBooksToComplete > 1 ? "s" : string.Empty,
                                              bl.AwardPoints,
                                              bl.AwardPoints > 1 ? "s" : string.Empty);
                    }

                    if (bl.AwardBadgeID > 0)
                    {
                        badge = DAL.Badge.FetchObject(bl.AwardBadgeID);
                        if (badge != null)
                        {
                            if (badge.HiddenFromPublic != true)
                            {
                                if (string.IsNullOrWhiteSpace(award))
                                {
                                    award = string.Format("Completing {0} task{1} will earn: <strong>a badge</strong>.",
                                                          bl.NumBooksToComplete,
                                                          bl.NumBooksToComplete > 1 ? "s" : string.Empty);
                                }
                                else
                                {
                                    award += " and <strong>a badge</strong>.";
                                }

                                BadgeImage.Text = string.Format("<img class=\"thumbnail disabled\" src=\"/images/badges/sm_{0}.png\" />", bl.AwardBadgeID);
                            }
                            else
                            {
                                badge = null;
                                if (string.IsNullOrWhiteSpace(award))
                                {
                                    award = string.Format("Completing {0} task{1} will earn: <strong>a secret badge</strong>.",
                                                          bl.NumBooksToComplete,
                                                          bl.NumBooksToComplete > 1 ? "s" : string.Empty);
                                }
                                else
                                {
                                    award += " and <strong>a secret badge</strong>.";
                                }
                                BadgeImage.Text = string.Empty;
                            }
                        }
                    }
                    else
                    {
                        BadgeImage.Text = string.Empty;
                        award          += ".";
                    }

                    BadgeImage.Visible = !string.IsNullOrEmpty(BadgeImage.Text);

                    if (!string.IsNullOrWhiteSpace(award))
                    {
                        lblPoints.Text    = award;
                        lblPoints.Visible = true;
                    }

                    var ds = BookListBooks.GetForDisplay(bl.BLID, patronId);

                    //Eval("NumBooksCompleted"), Eval("NumBooksToComplete")
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        int completed = 0;
                        foreach (DataRow row in ds.Tables[0].Rows)
                        {
                            if ((bool?)row["HasRead"] == true)
                            {
                                completed++;
                                if (completed >= bl.NumBooksToComplete)
                                {
                                    ChallengeCompleted = true;
                                    break;
                                }
                            }
                        }
                    }

                    rptr.DataSource = ds;
                    rptr.DataBind();

                    // begin social
                    var wt = new WebTools();

                    string systemName    = StringResources.getStringOrNull("system-name");
                    var    fbDescription = StringResources.getStringOrNull("facebook-description");
                    var    hashtags      = StringResources.getStringOrNull("socialmedia-hashtags");

                    string title = string.Format("{0} challenge: {1}",
                                                 systemName,
                                                 bl.ListName);

                    string description = string.Format("Check out this {0} challenge: {1}!",
                                                       systemName,
                                                       bl.ListName);

                    string twitDescrip = description;
                    if (twitDescrip.Length > 118)
                    {
                        // if it's longer than this it won't fit with the url, shorten it
                        twitDescrip = string.Format("Check this out: {0}!",
                                                    bl.ListName);
                    }

                    var baseUrl      = WebTools.GetBaseUrl(Request);
                    var challengeUrl = string.Format("{0}/Challenges/Details.aspx?ChallengeId={1}",
                                                     baseUrl,
                                                     bl.BLID);

                    string imagePath = null;
                    if (badge != null)
                    {
                        string potentialBadgePath = string.Format("~/Images/Badges/{0}.png",
                                                                  badge.BID);
                        if (System.IO.File.Exists(Server.MapPath(potentialBadgePath)))
                        {
                            imagePath = string.Format("{0}{1}",
                                                      baseUrl,
                                                      VirtualPathUtility.ToAbsolute(potentialBadgePath));
                        }
                    }

                    if (string.IsNullOrEmpty(imagePath))
                    {
                        imagePath = new GRA.Logic.Banner().FullMetadataBannerPath(baseUrl,
                                                                                  Session,
                                                                                  Server);
                    }

                    wt.AddOgMetadata(Metadata,
                                     title,
                                     wt.BuildFacebookDescription(description, hashtags, fbDescription),
                                     imagePath,
                                     challengeUrl,
                                     facebookApp: GetResourceString("facebook-appid"));

                    wt.AddTwitterMetadata(Metadata,
                                          title,
                                          description,
                                          imagePath,
                                          twitterUsername: GetResourceString("twitter-username"));

                    TwitterShare.NavigateUrl = wt.GetTwitterLink(description,
                                                                 Server.UrlEncode(challengeUrl),
                                                                 hashtags);
                    TwitterShare.Visible      = true;
                    FacebookShare.NavigateUrl = wt.GetFacebookLink(Server.UrlEncode(challengeUrl));
                    FacebookShare.Visible     = true;
                    // end social

                    this.ShowModal = true;
                }
            }
        }
コード例 #5
0
        protected void rptr_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            var BLID = int.Parse(e.CommandArgument.ToString());

            this.CompletedChallenge = e.CommandName.Equals(CompletedCommand,
                                                           StringComparison.OrdinalIgnoreCase);

            var bl = BookList.FetchObject(BLID);

            lblTitle.Text = bl.ListName;
            lblDesc.Text  = Server.HtmlDecode(bl.Description);

            string award = null;

            if (this.CompletedChallenge)
            {
                //completed
                award = string.Format("<span class=\"text-success lead\">Congratulations, you completed this challenge!</span>");
            }
            else
            {
                // not yet completed
                if (bl.AwardPoints > 0)
                {
                    award = string.Format("Completing <strong>{0} task{1}</strong> will earn: <strong>{2} point{3}</strong>",
                                          bl.NumBooksToComplete,
                                          bl.NumBooksToComplete > 1 ? "s" : string.Empty,
                                          bl.AwardPoints,
                                          bl.AwardPoints > 1 ? "s" : string.Empty);
                }

                if (bl.AwardBadgeID > 0)
                {
                    var badge = DAL.Badge.FetchObject(bl.AwardBadgeID);
                    if (badge != null)
                    {
                        if (badge.HiddenFromPublic != true)
                        {
                            if (string.IsNullOrWhiteSpace(award))
                            {
                                award = string.Format("Completing {0} task{1} will earn: <strong>a badge</strong>.",
                                                      bl.NumBooksToComplete,
                                                      bl.NumBooksToComplete > 1 ? "s" : string.Empty);
                            }
                            else
                            {
                                award += " and <strong>a badge</strong>.";
                            }

                            BadgeImage.Text = string.Format("<img class=\"thumbnail disabled\" src=\"/images/badges/sm_{0}.png\" />", bl.AwardBadgeID);
                        }
                        else
                        {
                            if (string.IsNullOrWhiteSpace(award))
                            {
                                award = string.Format("Completing {0} task{1} will earn: <strong>a secret badge</strong>.",
                                                      bl.NumBooksToComplete,
                                                      bl.NumBooksToComplete > 1 ? "s" : string.Empty);
                            }
                            else
                            {
                                award += " and <strong>a secret badge</strong>.";
                            }
                            BadgeImage.Text = string.Empty;
                        }
                    }
                }
            }

            BadgeImage.Visible = !string.IsNullOrEmpty(BadgeImage.Text);

            if (!string.IsNullOrWhiteSpace(award))
            {
                lblPoints.Text    = award;
                lblPoints.Visible = true;
            }

            lblTitle.Visible = true;
            lblDesc.Visible  = true;

            int patronId = -1;

            if (this.CurrentPatron != null)
            {
                patronId = this.CurrentPatron.PID;
            }

            var ds = BookListBooks.GetForDisplay(bl.BLID, patronId);

            rptr2.DataSource = ds;
            rptr2.DataBind();
            printLink.NavigateUrl = string.Format("~/Challenges/Details.aspx?ChallengeId={0}&print=1",
                                                  bl.BLID);
            detailsLink.NavigateUrl = string.Format("~/Challenges/Details.aspx?ChallengeId={0}",
                                                    bl.BLID);
            pnlDetail.Visible = true;

            if (this.CompletedChallenge ||
                this.CurrentPatron == null ||
                this.ProgramOpen == false)
            {
                btnSave.Visible = false;
            }
            else
            {
                btnSave.Visible = true;
            }

            this.ShowModal = true;
        }