Exemplo n.º 1
0
 public void DeleteTemporaryBL()
 {
     try {
         var e = BookList.FetchObject(int.Parse(lblPK.Text));
         e.Delete();
     } catch { }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            MasterPage.RequiredPermission = 4400;
            MasterPage.IsSecure           = true;

            if (!IsPostBack)
            {
                SetPageRibbon(StandardModuleRibbons.SetupRibbon());

                lblPK.Text = Session["BLL"] == null ? "" : Session["BLL"].ToString(); //Session["BLL"]= string.Empty;
                var bl = BookList.FetchObject(int.Parse(lblPK.Text));
                MasterPage.PageTitle = string.Format("Tasks in the \"{0}\" Challenge", bl.AdminName);
            }


            _mStrSortExp = String.Empty;
            if (!IsPostBack)
            {
                _mStrSortExp = String.Empty;
            }
            else
            {
                if (null != ViewState["_SortExp_"])
                {
                    _mStrSortExp = ViewState["_SortExp_"] as String;
                }

                if (null != ViewState["_Direction_"])
                {
                    _mSortDirection = (SortDirection)ViewState["_Direction_"];
                }
            }
        }
        protected void btnContinue3_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            var badge = LoadBadgeObject();

            badge.Insert();

            try
            {
                var badgePath = string.Format(Server.MapPath("~/images/Badges/"));
                System.IO.File.Copy(string.Format("{0}no_badge.png", badgePath),
                                    string.Format("{0}{1}.png", badgePath, badge.BID));
                System.IO.File.Copy(string.Format("{0}no_badge_sm.png", badgePath),
                                    string.Format("{0}sm_{1}.png", badgePath, badge.BID));
            }
            catch (Exception ex)
            {
                this.Log().Error("Couldn't copy no_badge images into new badge: {0}",
                                 ex.Message);
            }

            new SessionTools(Session).RemoveCache(Cache, CacheKey.BadgesActive);
            lblBID.Text = badge.BID.ToString();
            var bl = BookList.FetchObject(int.Parse(lblPK.Text));

            bl.AwardBadgeID = badge.BID;
            bl.Update();
            FileUploadCtl.FileName = lblBID.Text;
            FileUploadCtl.ProcessRender();
            OpenBadgesBadgeMaker.FileName = lblBID.Text;

            pnlLast.Visible      = true;
            pnlBadgeMore.Visible = false;
        }
Exemplo n.º 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
            {
                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;
            }
        }
Exemplo n.º 5
0
 public void DeleteTemporaryBLAndBadge()
 {
     try {
         var e = BookList.FetchObject(int.Parse(lblPK.Text));
         Badge.Delete(Badge.GetBadge(e.AwardBadgeID));
         e.Delete();
     } catch { }
 }
Exemplo n.º 6
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;
        }
 public void DeleteTemporaryBLAndBadge()
 {
     try
     {
         var e = BookList.FetchObject(int.Parse(lblPK.Text));
         Badge.Delete(Badge.GetBadge(e.AwardBadgeID));
         e.Delete();
         new SessionTools(Session).RemoveCache(Cache, CacheKey.ChallengesActive);
         new SessionTools(Session).RemoveCache(Cache, CacheKey.BadgesActive);
     }
     catch { }
 }
Exemplo n.º 8
0
        protected void btnContinue3_Click(object sender, System.Web.UI.ImageClickEventArgs e)
        {
            var obj = LoadBadgeObject();

            obj.Insert();
            Cache[CacheKey.BadgesActive] = true;
            lblBID.Text = obj.BID.ToString();
            var bl = BookList.FetchObject(int.Parse(lblPK.Text));

            bl.AwardBadgeID = obj.BID;
            bl.Update();
            FileUploadCtl.FileName = lblBID.Text;
            FileUploadCtl.ProcessRender();

            pnlLast.Visible      = true;
            pnlBadgeMore.Visible = false;
        }
Exemplo n.º 9
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;
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                SetPageRibbon(StandardModuleRibbons.SetupRibbon());
            }

            //MasterPage.RequiredPermission = PERMISSIONID;
            MasterPage.IsSecure = true;

            if (!IsPostBack)
            {
                lblPK.Text = Request["PK"].ToString();
                var bl = BookList.FetchObject(int.Parse(lblPK.Text));
                MasterPage.PageTitle = string.Format("Books on \"{0}\" Book List", bl.AdminName);
            }


            _mStrSortExp = String.Empty;
            if (!IsPostBack)
            {
                _mStrSortExp = String.Empty;
            }
            else
            {
                if (null != ViewState["_SortExp_"])
                {
                    _mStrSortExp = ViewState["_SortExp_"] as String;
                }

                if (null != ViewState["_Direction_"])
                {
                    _mSortDirection = (SortDirection)ViewState["_Direction_"];
                }
            }
        }
Exemplo n.º 11
0
        // points = 100
        // reason = PointAwardReason.MiniGameCompletion
        // MGID = Mini Game ID, if the reason is MiniGameCompletion, else 0
        //
        //
        // returns: a string based list of the badges they earned, or an empty string
        public string AwardPointsToPatron(int points, PointAwardReason reason,
                                          // Minigame
                                          int MGID = 0,
                                          // reading
                                          ActivityType readingActivity = ActivityType.Pages, int readingAmount = 0, string author = "", string title = "", string review = "",
                                          // event
                                          string eventCode = "", int eventID = 0,
                                          // book List
                                          int bookListID = 0,

                                          DateTime?forceDate = null
                                          )
        {
            if (forceDate != null)
            {
                now = (DateTime)forceDate;
            }

            string retValue = string.Empty;

            #region Reading - Log to PatronReadingLog
            PatronReadingLog rl = null;
            if (reason == PointAwardReason.Reading)
            {
                rl = new PatronReadingLog {
                    PID              = patron.PID,
                    ReadingType      = (int)readingActivity,
                    ReadingTypeLabel = (readingActivity).ToString(),
                    ReadingAmount    = readingAmount,
                    ReadingPoints    = points,
                    LoggingDate      = FormatHelper.ToNormalDate(now),
                    Author           = author.Trim(),
                    Title            = title.Trim(),
                    HasReview        = (review.Trim().Length > 0),
                    ReviewID         = 0
                };
                rl.Insert();

                // If there is a review, record the review
                if (review.Trim().Length > 0)
                {
                    var r = new PatronReview {
                        PID        = patron.PID,
                        PRLID      = rl.PRLID,
                        Author     = rl.Author,
                        Title      = rl.Title,
                        Review     = review.Trim(),
                        isApproved = false
                    };
                    r.Insert();

                    rl.ReviewID = r.PRID;
                    rl.Update();
                    HttpContext.Current.Session["LastPRID"] = r.PRID;
                }
            }
            #endregion

            #region Award PatronPoints

            var pp = new PatronPoints {
                PID                 = patron.PID,
                NumPoints           = points,
                AwardDate           = now,
                AwardReasonCd       = (int)reason,
                AwardReason         = PatronPoints.PointAwardReasonCdToDescription(reason),
                BadgeAwardedFlag    = false,
                isReading           = (reason == PointAwardReason.Reading),
                isEvent             = (reason == PointAwardReason.EventAttendance),
                isGameLevelActivity = (reason == PointAwardReason.MiniGameCompletion),
                isBookList          = (reason == PointAwardReason.BookListCompletion),
                isGame              = false,
                GameLevelActivityID = MGID,
                EventCode           = eventCode,
                EventID             = eventID,
                BookListID          = bookListID,
                LogID               = (rl == null ? 0 : rl.PRLID)
            };
            pp.Insert();

            var badgeAwarded = false;
            int badgeToAward = 0;               // <===========

            DAL.Minigame mg = null;
            if (reason == PointAwardReason.MiniGameCompletion)
            {
                mg           = DAL.Minigame.FetchObject(MGID);
                badgeAwarded = mg.AwardedBadgeID > 0;
                badgeToAward = mg.AwardedBadgeID;
            }
            if (reason == PointAwardReason.EventAttendance)
            {
                var evt = Event.GetEvent(eventID);
                badgeAwarded = evt == null ? false : evt.BadgeID > 0;
                badgeToAward = evt == null ? 0 : evt.BadgeID;
            }
            if (reason == PointAwardReason.BookListCompletion)
            {
                var bl = BookList.FetchObject(bookListID);
                ;
                badgeAwarded = (bl.AwardBadgeID > 0);
                badgeToAward = bl.AwardBadgeID;
            }

            DataSet pbds = null;
            if (badgeAwarded)
            {
                if (AwardBadgeToPatron(badgeToAward, patron, ref EarnedBadges))
                {
                    if (pp.PPID != 0)
                    {
                        pp.BadgeAwardedFlag = true;
                        pp.BadgeID          = badgeToAward;
                        pp.Update();
                    }
                }
            }

            #endregion

            #region If jumped level, award another badge(s)

            // since thay just earned points, check if they also advanced a level in the board game (if there is a board game for the program)
            EndingPoints = PatronPoints.GetTotalPatronPoints(patron.PID);
            EarnedBadge  = null;

            var earnedBadges2 = new List <Badge>();

            EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref earnedBadges2);
            pbds        = PatronBadges.GetAll(patron.PID);

            foreach (var badge in earnedBadges2)
            {
                EarnedBadge = badge;

                if (EarnedBadge != null)
                {
                    AwardBadgeToPatron(EarnedBadge.BID, patron, ref EarnedBadges);
                }
            }

            #endregion

            #region Check and give awards if any

            AwardBadgeToPatronViaMatchingAwards(patron, ref EarnedBadges);

            #endregion

            #region Prepare return code
            // did they earn one or more badges?
            if (EarnedBadges.Count > 0)
            {
                retValue = string.Join("|", EarnedBadges.Select(b => b.BID).Distinct());
            }
            #endregion

            return(retValue);
        }
Exemplo n.º 12
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;
        }
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Setup/BookListAddEdit.aspx";

            if (e.CommandName.ToLower() == "addrecord")
            {
                Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Response.Redirect(String.Format("{0}?PK={1}", editpage, key));
            }

            if (e.CommandName.ToLower() == "saveandbooks")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Response.Redirect(String.Format("{0}?PK={1}", "~/ControlRoom/Modules/Setup/BookListBooksList.aspx", key));
            }

            if (e.CommandName.ToLower() == "deleterecord")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = new BookList();
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        BookList.FetchObject(key).Delete();

                        LoadData();
                        var masterPage = (IControlRoomMaster)Master;
                        if (masterPage != null)
                        {
                            masterPage.PageMessage = SRPResources.DeleteOK;
                        }
                    }
                    else
                    {
                        var    masterPage = (IControlRoomMaster)Master;
                        string message    = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        if (masterPage != null)
                        {
                            masterPage.PageError = message;
                        }
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    if (masterPage != null)
                    {
                        masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                    }
                }
            }
        }
        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;
                }
            }
        }
Exemplo n.º 15
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ProgramOpen)
            {
                return;
            }

            var now = DateTime.Now;
            var onlyCheckedBoxes = true;
            var selBLI           = 0;
            var readCount        = 0;
            var neeedCount       = 0;
            var BLID             = -1;

            foreach (RepeaterItem item in rptr2.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    if (BLID < 0)
                    {
                        BLID       = int.Parse(((Label)item.FindControl("BLID")).Text);
                        neeedCount = BookList.FetchObject(BLID).NumBooksToComplete;
                    }
                    var chkRead = (CheckBox)item.FindControl("chkRead");
                    var PBLBID  = int.Parse(((Label)item.FindControl("PBLBID")).Text);
                    var BLBID   = int.Parse(((Label)item.FindControl("BLBID")).Text);

                    selBLI = BLID;
                    var pbl = new PatronBookLists();
                    if (PBLBID != 0)
                    {
                        pbl = PatronBookLists.FetchObject(PBLBID);
                    }
                    pbl.BLBID       = BLBID;
                    pbl.BLID        = BLID;
                    pbl.PID         = ((Patron)Session["Patron"]).PID;
                    pbl.LastModDate = now;

                    pbl.HasReadFlag = chkRead.Checked;
                    if (!pbl.HasReadFlag)
                    {
                        onlyCheckedBoxes = false;
                    }
                    else
                    {
                        readCount++;
                    }

                    if (PBLBID != 0)
                    {
                        pbl.Update();
                    }
                    else
                    {
                        pbl.Insert();
                    }
                }
            }

            string success = StringResources.getString("challenges-progress-saved");

            new SessionTools(Session).AlertPatron(success,
                                                  glyphicon: "check");

            // read the entire book list!  Award points and badges
            if ((neeedCount == 0 && onlyCheckedBoxes) || (neeedCount <= readCount))
            {
                success = StringResources.getString("challenges-completed");

                new SessionTools(Session).AlertPatron(success, glyphicon: "star");

                var bl = BookList.FetchObject(selBLI);

                if (PatronPoints.HasEarnedBookList(((Patron)Session["Patron"]).PID, selBLI))
                {
                    PopulateChallengeList();
                    return;
                }

                if (bl.AwardBadgeID != 0 || bl.AwardPoints != 0)
                {
                    success = StringResources.getString("challenges-completed-badge");
                    new SessionTools(Session).AlertPatron(success,
                                                          glyphicon: "certificate");

                    var pa      = new AwardPoints(((Patron)Session["Patron"]).PID);
                    var sBadges = pa.AwardPointsToPatron(bl.AwardPoints, PointAwardReason.BookListCompletion,
                                                         bookListID: bl.BLID);
                    if (sBadges.Length > 0)
                    {
                        new SessionTools(Session).EarnedBadges(sBadges);
                    }
                }
            }
            PopulateChallengeList();
        }
        // points = 100
        // reason = PointAwardReason.MiniGameCompletion
        // MGID = Mini Game ID, if the reason is MiniGameCompletion, else 0
        //
        //
        // returns: a string based list of the badges they earned, or an empty string
        public string AwardPointsToPatron(int points, PointAwardReason reason,
                                          // Minigame
                                          int MGID = 0,
                                          // reading
                                          ActivityType readingActivity = ActivityType.Pages, int readingAmount = 0, string author = "", string title = "", string review = "",
                                          // event
                                          string eventCode = "", int eventID = 0,
                                          // book List
                                          int bookListID = 0,

                                          DateTime?forceDate = null
                                          )
        {
            if (forceDate != null)
            {
                now = (DateTime)forceDate;
            }

            string retValue = "";

            #region Reading - Log to PatronReadingLog
            PatronReadingLog rl = null;
            if (reason == PointAwardReason.Reading)
            {
                rl = new PatronReadingLog
                {
                    PID              = patron.PID,
                    ReadingType      = (int)readingActivity,
                    ReadingTypeLabel = (readingActivity).ToString(),
                    ReadingAmount    = readingAmount,
                    ReadingPoints    = points,
                    LoggingDate      = FormatHelper.ToNormalDate(now),
                    Author           = author.Trim(),
                    Title            = title.Trim(),
                    HasReview        = (review.Trim().Length > 0),
                    ReviewID         = 0
                };
                rl.Insert();

                // If there is a review, record the review
                if (review.Trim().Length > 0)
                {
                    var r = new PatronReview
                    {
                        PID        = patron.PID,
                        PRLID      = rl.PRLID,
                        Author     = rl.Author,
                        Title      = rl.Title,
                        Review     = review.Trim(),
                        isApproved = false
                    };
                    r.Insert();

                    rl.ReviewID = r.PRID;
                    rl.Update();
                }
            }
            #endregion

            #region Award PatronPoints

            var pp = new PatronPoints
            {
                PID                 = patron.PID,
                NumPoints           = points,
                AwardDate           = now,
                AwardReasonCd       = (int)reason,
                AwardReason         = PatronPoints.PointAwardReasonCdToDescription(reason),
                BadgeAwardedFlag    = false,
                isReading           = (reason == PointAwardReason.Reading),
                isEvent             = (reason == PointAwardReason.EventAttendance),
                isGameLevelActivity = (reason == PointAwardReason.MiniGameCompletion),
                isBookList          = (reason == PointAwardReason.BookListCompletion),
                isGame              = false,
                GameLevelActivityID = MGID,
                EventCode           = eventCode,
                EventID             = eventID,
                BookListID          = bookListID,
                LogID               = (rl == null ? 0 : rl.PRLID)
            };
            pp.Insert();

            var badgeAwarded = false;
            int badgeToAward = 0;               // <===========

            DAL.Minigame mg = null;
            if (reason == PointAwardReason.MiniGameCompletion)
            {
                mg           = DAL.Minigame.FetchObject(MGID);
                badgeAwarded = mg.AwardedBadgeID > 0;
                badgeToAward = mg.AwardedBadgeID;
            }
            if (reason == PointAwardReason.EventAttendance)
            {
                var evt = Event.GetEvent(eventID);
                badgeAwarded = evt.BadgeID > 0;
                badgeToAward = evt.BadgeID;
            }
            if (reason == PointAwardReason.BookListCompletion)
            {
                var bl = BookList.FetchObject(bookListID);;
                badgeAwarded = (bl.AwardBadgeID > 0);
                badgeToAward = bl.AwardBadgeID;
            }

            DataSet pbds = null;
            //DataTable newTable = null;
            if (badgeAwarded)
            {
                if (AwardBadgeToPatron(badgeToAward, patron, ref EarnedBadges))
                {
                    if (pp.PPID != 0)
                    {
                        pp.BadgeAwardedFlag = true;
                        pp.BadgeID          = badgeToAward;
                        pp.Update();
                    }
                }
                #region AwardBadgeToPatron code
                //// check if badge was already earned...
                //pbds = PatronBadges.GetAll(patron.PID);
                //var a = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == badgeToAward);

                //newTable = new DataTable();
                //try { newTable = a.CopyToDataTable(); } catch { }

                //// badge not found, award it!
                //if (newTable.Rows.Count == 0)
                //{
                //    var pb = new PatronBadges { BadgeID = badgeToAward, DateEarned = now, PID = patron.PID };
                //    pb.Insert();

                //    EarnedBadge = Badge.GetBadge(badgeToAward);
                //    EarnedBadges.Add(EarnedBadge);

                //    //if badge generates notification, then generate the notification
                //    if (EarnedBadge.GenNotificationFlag)
                //    {
                //        var not = new Notifications
                //        {
                //            PID_To = patron.PID,
                //            PID_From = 0,  //0 == System Notification
                //            Subject = EarnedBadge.NotificationSubject,
                //            Body = EarnedBadge.NotificationBody,
                //            isQuestion = false,
                //            AddedDate = now,
                //            LastModDate = now,
                //            AddedUser = patron.Username,
                //            LastModUser = "******"
                //        };
                //        not.Insert();
                //    }

                //    //if badge generates prize, then generate the prize
                //    if (EarnedBadge.IncludesPhysicalPrizeFlag)
                //    {
                //        var ppp = new DAL.PatronPrizes
                //                      {
                //                          PID = patron.PID,
                //                          PrizeSource = 1,
                //                          PrizeName = EarnedBadge.PhysicalPrizeName,
                //                          RedeemedFlag = false,
                //                          AddedUser = patron.Username,
                //                          LastModUser = "******",
                //                          AddedDate = now,
                //                          LastModDate = now
                //                      };

                //        ppp.Insert();
                //    }



                //    // if badge generates award code, then generate the code
                //    if (EarnedBadge.AssignProgramPrizeCode)
                //    {
                //        var RewardCode = "";
                //        // get the Code value
                //        // save the code value for the patron
                //        RewardCode = ProgramCodes.AssignCodeForPatron(patron.ProgID, patron.ProgID);

                //        // generate the notification
                //        var not = new Notifications
                //        {
                //            PID_To = patron.PID,
                //            PID_From = 0,  //0 == System Notification
                //            Subject = EarnedBadge.PCNotificationSubject,
                //            Body = EarnedBadge.PCNotificationBody.Replace("{ProgramRewardCode}", RewardCode),
                //            isQuestion = false,
                //            AddedDate = now,
                //            LastModDate = now,
                //            AddedUser = patron.Username,
                //            LastModUser = "******"
                //        };
                //        not.Insert();
                //    }

                //    if (pp.PPID != 0)
                //    {
                //        pp.BadgeAwardedFlag = true;
                //        pp.BadgeID = badgeToAward;
                //        pp.Update();
                //    }
                //}
                #endregion
            }

            #endregion

            #region If jumped level, award another badge(s)

            // since thay just earned points, check if they also advanced a level in the board game (if there is a board game for the program)
            EndingPoints = PatronPoints.GetTotalPatronPoints(patron.PID);
            EarnedBadge  = null;

            var earnedBadges2 = new List <Badge>();

            EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref earnedBadges2);
            pbds        = PatronBadges.GetAll(patron.PID);

            foreach (var badge in earnedBadges2)
            {
                EarnedBadge = badge;

                if (EarnedBadge != null)
                {
                    AwardBadgeToPatron(EarnedBadge.BID, patron, ref EarnedBadges);
                }

                #region AwardBadgeToPatron call2
                //// check if badge was already earned...
                //if (EarnedBadge != null)
                //{
                //    var aa = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == badgeToAward);

                //    newTable = new DataTable();
                //    try { newTable = aa.CopyToDataTable(); }
                //    catch { }

                //    // badge not found, award it!
                //}
                //if (EarnedBadge != null && newTable != null && newTable.Rows.Count == 0)
                //{
                //    // Award the badge

                //    EarnedBadges.Add(badge);  // Add badge tot he list used to display to user ...

                //    var newPBID = 0;
                //    var pb = new PatronBadges { BadgeID = EarnedBadge.BID, DateEarned = now, PID = patron.PID };
                //    pb.Insert();
                //    newPBID = pb.PBID;

                //    //if badge generates notification, then generate the notification
                //    if (EarnedBadge.GenNotificationFlag)
                //    {
                //        var not = new Notifications
                //        {
                //            PID_To = patron.PID,
                //            PID_From = 0,  //0 == System Notification
                //            Subject = EarnedBadge.NotificationSubject,
                //            Body = EarnedBadge.NotificationBody,
                //            isQuestion = false,
                //            AddedDate = now,
                //            LastModDate = now,
                //            AddedUser = patron.Username,
                //            LastModUser = "******"
                //        };
                //        not.Insert();
                //    }

                //    //if badge generates prize, then generate the prize
                //    if (EarnedBadge.IncludesPhysicalPrizeFlag)
                //    {
                //        var ppp = new DAL.PatronPrizes
                //        {
                //            PID = patron.PID,
                //            PrizeSource = 1,
                //            PrizeName = EarnedBadge.PhysicalPrizeName,
                //            RedeemedFlag = false,
                //            AddedUser = patron.Username,
                //            LastModUser = "******",
                //            AddedDate = now,
                //            LastModDate = now
                //        };

                //        ppp.Insert();
                //    }

                //    // if badge generates award code, then generate the code
                //    if (EarnedBadge.AssignProgramPrizeCode)
                //    {
                //        var RewardCode = "";
                //        // get the Code value
                //        // save the code value for the patron
                //        RewardCode = ProgramCodes.AssignCodeForPatron(patron.ProgID, patron.ProgID);

                //        // generate the notification
                //        var not = new Notifications
                //        {
                //            PID_To = patron.PID,
                //            PID_From = 0,  //0 == System Notification
                //            Subject = EarnedBadge.PCNotificationSubject,
                //            Body = EarnedBadge.PCNotificationBody.Replace("{ProgramRewardCode}", RewardCode),
                //            isQuestion = false,
                //            AddedDate = now,
                //            LastModDate = now,
                //            AddedUser = patron.Username,
                //            LastModUser = "******"
                //        };
                //        not.Insert();
                //    }
                //}
                #endregion
            }

            #region deprecated - replaced by abbility to earn multiple badges above
            //EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref EarnedBadges);

            //// check if badge was already earned...
            //if (EarnedBadge != null) {
            //    pbds = PatronBadges.GetAll(patron.PID);
            //    var aa = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == badgeToAward);

            //    newTable = new DataTable();
            //    try { newTable = aa.CopyToDataTable(); } catch { }

            //    // badge not found, award it!
            //}
            //if (EarnedBadge != null && newTable!= null && newTable.Rows.Count == 0)
            //{
            //    // Award the badge
            //    var newPBID = 0;
            //    var pb = new PatronBadges { BadgeID = EarnedBadge.BID, DateEarned = now, PID = patron.PID };
            //    pb.Insert();
            //    newPBID = pb.PBID;

            //    //if badge generates notification, then generate the notification
            //    if (EarnedBadge.GenNotificationFlag)
            //    {
            //        var not = new Notifications
            //        {
            //            PID_To = patron.PID,
            //            PID_From = 0,  //0 == System Notification
            //            Subject = EarnedBadge.NotificationSubject,
            //            Body = EarnedBadge.NotificationBody,
            //            isQuestion = false,
            //            AddedDate = now,
            //            LastModDate = now,
            //            AddedUser = patron.Username,
            //            LastModUser = "******"
            //        };
            //        not.Insert();
            //    }

            //    //if badge generates prize, then generate the prize
            //    if (EarnedBadge.IncludesPhysicalPrizeFlag)
            //    {
            //        var ppp = new DAL.PatronPrizes
            //        {
            //            PID = patron.PID,
            //            PrizeSource = 1,
            //            PrizeName = EarnedBadge.PhysicalPrizeName,
            //            RedeemedFlag = false,
            //            AddedUser = patron.Username,
            //            LastModUser = "******",
            //            AddedDate = now,
            //            LastModDate = now
            //        };

            //        ppp.Insert();
            //    }

            //    // if badge generates award code, then generate the code
            //    if (EarnedBadge.AssignProgramPrizeCode)
            //    {
            //        var RewardCode = "";
            //        // get the Code value
            //        // save the code value for the patron
            //        RewardCode = ProgramCodes.AssignCodeForPatron(patron.ProgID, patron.ProgID);

            //        // generate the notification
            //        var not = new Notifications
            //        {
            //            PID_To = patron.PID,
            //            PID_From = 0,  //0 == System Notification
            //            Subject = EarnedBadge.PCNotificationSubject,
            //            Body = EarnedBadge.PCNotificationBody.Replace("{ProgramRewardCode}", RewardCode),
            //            isQuestion = false,
            //            AddedDate = now,
            //            LastModDate = now,
            //            AddedUser = patron.Username,
            //            LastModUser = "******"
            //        };
            //        not.Insert();
            //    }
            #endregion


            #endregion

            #region Check and give awards if any

            AwardBadgeToPatronViaMatchingAwards(patron, ref EarnedBadges);

            #endregion

            #region Prepare return code
            // did they earn one or more badges?
            if (EarnedBadges.Count > 0)
            {
                var badges = EarnedBadges.Count.ToString();
                //foreach(Badge b in EarnedBadges)
                //{
                //    badges = badges + "|" + b.BID.ToString();
                //}
                badges = EarnedBadges.Aggregate(badges, (current, b) => current + "|" + b.BID.ToString());
                //Response.Redirect("~/BadgeAward.aspx?b=" + badges);
                retValue = badges;
            }
            #endregion

            return(retValue);
        }
Exemplo n.º 17
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var now = DateTime.Now;
            var onlyCheckedBoxes = true;
            var selBLI           = 0;

            foreach (RepeaterItem item in rptr2.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    var chkRead = (CheckBox)item.FindControl("chkRead");
                    var PBLBID  = int.Parse(((Label)item.FindControl("PBLBID")).Text);
                    var BLBID   = int.Parse(((Label)item.FindControl("BLBID")).Text);
                    var BLID    = int.Parse(((Label)item.FindControl("BLID")).Text);
                    selBLI = BLID;
                    var pbl = new PatronBookLists();
                    if (PBLBID != 0)
                    {
                        pbl = PatronBookLists.FetchObject(PBLBID);
                    }
                    pbl.BLBID       = BLBID;
                    pbl.BLID        = BLID;
                    pbl.PID         = ((Patron)Session["Patron"]).PID;
                    pbl.LastModDate = now;

                    pbl.HasReadFlag = chkRead.Checked;
                    if (!pbl.HasReadFlag)
                    {
                        onlyCheckedBoxes = false;
                    }

                    if (PBLBID != 0)
                    {
                        pbl.Update();
                    }
                    else
                    {
                        pbl.Insert();
                    }
                }
            }

            lblMessage.Visible = true;

            // read the entire book list!  Award points and badges
            if (onlyCheckedBoxes)
            {
                var bl = BookList.FetchObject(selBLI);

                if (PatronPoints.HasEarnedBookList(((Patron)Session["Patron"]).PID, selBLI))
                {
                    return;
                }


                if (bl.AwardBadgeID != 0 || bl.AwardPoints != 0)
                {
                    var pa      = new AwardPoints(((Patron)Session["Patron"]).PID);
                    var sBadges = pa.AwardPointsToPatron(bl.AwardPoints, PointAwardReason.BookListCompletion,
                                                         bookListID: bl.BLID);
                    if (sBadges.Length > 0)
                    {
                        Response.Redirect("~/BadgeAward.aspx?b=" + sBadges);
                    }
                }
            }
        }