Exemple #1
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);
                    }
                }
            }
        }
Exemple #2
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();
        }