Пример #1
0
        public bool SaveAccount()
        {
            try
            {
                var      patron = (Patron)Session["Patron"];
                var      p      = new Patron();
                DateTime _d;
                var      DOB = rptr.Items[0].FindControl("DOB") as TextBox;
                if (DOB != null && DOB.Text != "")
                {
                    if (DateTime.TryParse(DOB.Text, out _d))
                    {
                        p.DOB = _d;
                    }
                }

                p.Age = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("Age")).Text);

                p.ProgID   = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("ProgID")).SelectedValue);
                p.Username = ((TextBox)(rptr.Items[0]).FindControl("Username")).Text;
                p.Password = ((TextBox)(rptr.Items[0]).FindControl("Password")).Text;

                p.IsMasterAccount = false;
                p.MasterAcctPID   = patron.PID;

                p.SchoolGrade    = ((TextBox)(rptr.Items[0]).FindControl("SchoolGrade")).Text;
                p.FirstName      = ((TextBox)(rptr.Items[0]).FindControl("FirstName")).Text;
                p.MiddleName     = ((TextBox)(rptr.Items[0]).FindControl("MiddleName")).Text;
                p.LastName       = ((TextBox)(rptr.Items[0]).FindControl("LastName")).Text;
                p.Gender         = ((DropDownList)(rptr.Items[0]).FindControl("Gender")).SelectedValue;
                p.EmailAddress   = ((TextBox)(rptr.Items[0]).FindControl("EmailAddress")).Text;
                p.PhoneNumber    = ((TextBox)(rptr.Items[0]).FindControl("PhoneNumber")).Text;
                p.PhoneNumber    = FormatHelper.FormatPhoneNumber(p.PhoneNumber);
                p.StreetAddress1 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress1")).Text;
                p.StreetAddress2 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress2")).Text;
                p.City           = ((TextBox)(rptr.Items[0]).FindControl("City")).Text;
                p.State          = ((TextBox)(rptr.Items[0]).FindControl("State")).Text;
                p.ZipCode        = ((TextBox)(rptr.Items[0]).FindControl("ZipCode")).Text;
                p.ZipCode        = FormatHelper.FormatZipCode(p.ZipCode);

                p.Country = ((TextBox)(rptr.Items[0]).FindControl("Country")).Text;
                p.County  = ((TextBox)(rptr.Items[0]).FindControl("County")).Text;
                p.ParentGuardianFirstName  = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianFirstName")).Text;
                p.ParentGuardianLastName   = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianLastName")).Text;
                p.ParentGuardianMiddleName = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianMiddleName")).Text;
                p.LibraryCard = ((TextBox)(rptr.Items[0]).FindControl("LibraryCard")).Text;

                //p.District = ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue;
                //p.SDistrict = ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt();

                p.PrimaryLibrary = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("PrimaryLibrary")).SelectedValue);
                p.SchoolName     = ((DropDownList)(rptr.Items[0]).FindControl("SchoolName")).SelectedValue;
                p.SchoolType     = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue);

                var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary);
                if (lc != null)
                {
                    p.District = lc.DistrictID == 0 ? ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue  : lc.DistrictID.ToString();
                }
                else
                {
                    p.District = ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue;
                }
                var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt());
                if (sc != null)
                {
                    p.SDistrict  = sc.DistrictID == 0 ? ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt() : sc.DistrictID;
                    p.SchoolType = sc.SchTypeID == 0 ? FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue) : sc.SchTypeID;
                }
                else
                {
                    p.SDistrict = ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt();
                }

                p.Teacher        = ((TextBox)(rptr.Items[0]).FindControl("Teacher")).Text;
                p.GroupTeamName  = ((TextBox)(rptr.Items[0]).FindControl("GroupTeamName")).Text;
                p.LiteracyLevel1 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel1")).Text);
                p.LiteracyLevel2 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel2")).Text);

                p.ParentPermFlag = true;
                p.Over18Flag     = true;
                p.ShareFlag      = true;
                p.TermsOfUseflag = true;

                var cr = CustomRegistrationFields.FetchObject();
                p.Custom1 = cr.DDValues1 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom1")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom1DD")).SelectedValue;
                p.Custom2 = cr.DDValues2 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom2")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom2DD")).SelectedValue;
                p.Custom3 = cr.DDValues3 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom3")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom3DD")).SelectedValue;
                p.Custom4 = cr.DDValues4 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom4")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom4DD")).SelectedValue;
                p.Custom5 = cr.DDValues5 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom5")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom5DD")).SelectedValue;

                p.AvatarID = FormatHelper.SafeToInt(((System.Web.UI.HtmlControls.HtmlInputText)rptr.Items[0].FindControl("AvatarID")).Value);


                if (p.IsValid(BusinessRulesValidationMode.INSERT))
                {
                    p.Insert();

                    var prog = Programs.FetchObject(p.ProgID);
                    var list = new List <Badge>();
                    if (prog.RegistrationBadgeID != 0)
                    {
                        AwardPoints.AwardBadgeToPatron(prog.RegistrationBadgeID, p, ref list);
                    }
                    AwardPoints.AwardBadgeToPatronViaMatchingAwards(p, ref list);

                    patron.IsMasterAccount = true;
                    patron.Update();
                }
                else
                {
                    string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                    foreach (BusinessRulesValidationMessage m in p.ErrorCodes)
                    {
                        message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                    }
                    message       = string.Format("{0}</ul>", message);
                    lblError.Text = message;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                lblError.Text = String.Format(SRPResources.ApplicationError1, ex.Message);

                return(false);
            }
            return(true);
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            var txtCount = txtCountSubmitted.Text.Trim();
            var txtCode  = txtProgramCode.Text.Trim();

            // ---------------------------------------------------------------------------------------------------
            if (txtCount.Length > 0 && txtCode.Length > 0)
            {
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Text      = "Please enter either how much you have read OR a code, but not both.<br><br>";
                return;
            }

            if (txtCount.Length == 0 && txtCode.Length == 0)
            {
                lblMessage.ForeColor = System.Drawing.Color.Red;
                lblMessage.Text      = "Please enter either how much you have read OR a code.<br><br>";
                return;
            }
            // ---------------------------------------------------------------------------------------------------

            int PID  = int.Parse(lblPID.Text);
            int PGID = int.Parse(lblPGID.Text);

            var pa      = new AwardPoints(PID);
            var sBadges = "";
            var points  = 0;

            #region Reading
            // ---------------------------------------------------------------------------------------------------
            // Logging reading ...
            //Badge EarnedBadge;
            if (txtCount.Length > 0)
            {
                var intCount = 0;
                if (!int.TryParse(txtCount, out intCount))
                {
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Text      = "How much you have read must be a number.<br><br>";
                    return;
                }

                if (intCount < 0)
                {
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Text      = "Hmmm, you must enter a positive number...<br><br>";
                    return;
                }

                int maxAmountForLogging       = 0;
                int maxPointsPerDayForLogging = SRPSettings.GetSettingValue("MaxPtsDay").SafeToInt();
                switch (int.Parse(rbActivityType.SelectedValue))
                {
                case 0: maxAmountForLogging = SRPSettings.GetSettingValue("MaxBook").SafeToInt();
                    break;

                case 1: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPage").SafeToInt();
                    break;

                //case 2: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPar").SafeToInt();
                //    break;
                case 3: maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                    break;

                default: maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                    break;
                }

                if (intCount > maxAmountForLogging)
                {
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Text      = string.Format("That is an awful lot of reading... unfortunately the maximum you can submit at one time is {0} {1}.<br><br>",
                                                         maxAmountForLogging, ((ActivityType)int.Parse(rbActivityType.SelectedValue)).ToString());
                    return;
                }

                // convert pages/minutes/etc. to points
                var pc = new ProgramGamePointConversion();
                pc.FetchByActivityId(PGID, int.Parse(rbActivityType.SelectedValue));
                points = Convert.ToInt32(intCount * pc.PointCount / pc.ActivityCount);

                var allPointsToday = PatronPoints.GetTotalPatronPoints(PID, DateTime.Now);
                if (intCount + allPointsToday > maxPointsPerDayForLogging)
                {
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Text      = string.Format("We are sorry, you have reached the maximum amount of points you are allowed to log in a single day, regardless of how the points were earned. Please come back and and log them tomorrow.<br><br>");
                    return;
                }



                sBadges = pa.AwardPointsToPatron(points, PointAwardReason.Reading,
                                                 0,
                                                 (ActivityType)pc.ActivityTypeId, intCount, txtAuthor.Text.Trim(), txtTitle.Text.Trim(), Review.Text.Trim());
            }
            #endregion

            #region Event Attendance
            // Logging event attendance
            if (txtCode.Length > 0)
            {
                // verify event code was not previously redeemed
                if (PatronPoints.HasRedeemedKeywordPoints(PID, txtCode))
                {
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Text      = "This code has already been redeemend for your account.<br><br>";
                    return;
                }

                // get event for that code, get the # points
                var ds = Event.GetEventByEventCode(pa.pgm.StartDate.ToShortDateString(),
                                                   DateTime.Now.ToShortDateString(), txtCode);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    lblMessage.ForeColor = System.Drawing.Color.Red;
                    lblMessage.Text      = "This code is not valid.<br><br>";
                    return;
                }
                var EID = (int)ds.Tables[0].Rows[0]["EID"];
                var evt = Event.GetEvent(EID);
                points = evt.NumberPoints;
                //var newPBID = 0;


                if (evt.BadgeID != 0)
                {
                    sBadges = pa.AwardPointsToPatron(points, PointAwardReason.EventAttendance,
                                                     eventCode: txtCode, eventID: EID);
                }
            }
            #endregion

            if (sBadges != "")
            {
                Session["GoToUrl"] = GoToUrl;
                Response.Redirect("~/BadgeAward.aspx?b=" + sBadges);
            }

            lblMessage.ForeColor = System.Drawing.Color.Green;
            lblMessage.Text      = string.Format("Your reading activity has been logged.<br>You have earned {0} points.<br><br>", points);
            txtAuthor.Text       = txtTitle.Text = txtCountSubmitted.Text = Review.Text = txtProgramCode.Text = "";
            btnSubmit.Visible    = false;
            btnReSubmit.Visible  = true;
            EntryTable.Visible   = false;
            //return;))

            var c = ((BaseSRPPage)Page).FindControlRecursive(Page, "MyPointsControl1");
            if (c != null)
            {
                ((MyPointsControl)c).LoadData();
            }

            c = ((BaseSRPPage)Page).FindControlRecursive(Page, "LeaderBoardControl1");
            if (c != null)
            {
                ((LeaderBoardControl)c).LoadData();
            }

            if (!StayOnPage)
            {
                Response.Redirect(GoToUrl);
            }
        }
        public bool SaveAccount()
        {
            try
            {
                var      p = new Patron();
                DateTime _d;
                var      DOB = rptr.Items[0].FindControl("DOB") as TextBox;
                if (DOB != null && DOB.Text != "")
                {
                    if (DateTime.TryParse(DOB.Text, out _d))
                    {
                        p.DOB = _d;
                    }
                }

                p.Age = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("Age")).Text);

                p.ProgID   = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("ProgID")).SelectedValue);
                p.Username = ((TextBox)(rptr.Items[0]).FindControl("Username")).Text;
                p.Password = ((TextBox)(rptr.Items[0]).FindControl("Password")).Text;

                var famAcct = (RadioButtonList)rptr.Items[0].FindControl("FamilyAccount");
                p.IsMasterAccount = (famAcct.SelectedValue == "Yes" && MasterPID.Text.Length == 0);

                p.SchoolGrade    = ((TextBox)(rptr.Items[0]).FindControl("SchoolGrade")).Text;
                p.FirstName      = ((TextBox)(rptr.Items[0]).FindControl("FirstName")).Text;
                p.MiddleName     = ((TextBox)(rptr.Items[0]).FindControl("MiddleName")).Text;
                p.LastName       = ((TextBox)(rptr.Items[0]).FindControl("LastName")).Text;
                p.Gender         = ((DropDownList)(rptr.Items[0]).FindControl("Gender")).SelectedValue;
                p.EmailAddress   = ((TextBox)(rptr.Items[0]).FindControl("EmailAddress")).Text;
                p.PhoneNumber    = ((TextBox)(rptr.Items[0]).FindControl("PhoneNumber")).Text;
                p.PhoneNumber    = FormatHelper.FormatPhoneNumber(p.PhoneNumber);
                p.StreetAddress1 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress1")).Text;
                p.StreetAddress2 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress2")).Text;
                p.City           = ((TextBox)(rptr.Items[0]).FindControl("City")).Text;
                p.State          = ((TextBox)(rptr.Items[0]).FindControl("State")).Text;
                p.ZipCode        = ((TextBox)(rptr.Items[0]).FindControl("ZipCode")).Text;
                p.ZipCode        = FormatHelper.FormatZipCode(p.ZipCode);

                p.Country = ((TextBox)(rptr.Items[0]).FindControl("Country")).Text;
                p.County  = ((TextBox)(rptr.Items[0]).FindControl("County")).Text;
                p.ParentGuardianFirstName  = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianFirstName")).Text;
                p.ParentGuardianLastName   = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianLastName")).Text;
                p.ParentGuardianMiddleName = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianMiddleName")).Text;
                p.LibraryCard = ((TextBox)(rptr.Items[0]).FindControl("LibraryCard")).Text;

                //p.District = ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue;
                //p.SDistrict = ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt();

                p.PrimaryLibrary = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("PrimaryLibrary")).SelectedValue);
                p.SchoolName     = ((DropDownList)(rptr.Items[0]).FindControl("SchoolName")).SelectedValue;
                p.SchoolType     = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue);

                var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary);
                if (lc != null)
                {
                    p.District = lc.DistrictID == 0 ? ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue : lc.DistrictID.ToString();
                }
                else
                {
                    p.District = ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue;
                }
                var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt());
                if (sc != null)
                {
                    p.SDistrict  = sc.DistrictID == 0 ? ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt() : sc.DistrictID;
                    p.SchoolType = sc.SchTypeID == 0 ? FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue) : sc.SchTypeID;
                }
                else
                {
                    p.SDistrict = ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt();
                }


                p.Teacher        = ((TextBox)(rptr.Items[0]).FindControl("Teacher")).Text;
                p.GroupTeamName  = ((TextBox)(rptr.Items[0]).FindControl("GroupTeamName")).Text;
                p.LiteracyLevel1 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel1")).Text);
                p.LiteracyLevel2 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel2")).Text);

                p.ParentPermFlag = ((CheckBox)(rptr.Items[0]).FindControl("ParentPermFlag")).Checked;
                p.Over18Flag     = int.Parse(RegistrationAge.Text) > 18;
                p.ShareFlag      = ((CheckBox)(rptr.Items[0]).FindControl("ShareFlag")).Checked;
                p.TermsOfUseflag = ((CheckBox)(rptr.Items[0]).FindControl("TermsOfUseflag")).Checked;

                var cr = CustomRegistrationFields.FetchObject();
                p.Custom1 = cr.DDValues1 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom1")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom1DD")).SelectedValue;
                p.Custom2 = cr.DDValues2 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom2")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom2DD")).SelectedValue;
                p.Custom3 = cr.DDValues3 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom3")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom3DD")).SelectedValue;
                p.Custom4 = cr.DDValues4 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom4")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom4DD")).SelectedValue;
                p.Custom5 = cr.DDValues5 == "" ? ((TextBox)(rptr.Items[0]).FindControl("Custom5")).Text : ((DropDownList)(rptr.Items[0]).FindControl("Custom5DD")).SelectedValue;

                //p.Custom1 = ((TextBox)(rptr.Items[0]).FindControl("Custom1")).Text;
                //p.Custom2 = ((TextBox)(rptr.Items[0]).FindControl("Custom2")).Text;
                //p.Custom3 = ((TextBox)(rptr.Items[0]).FindControl("Custom3")).Text;
                //p.Custom4 = ((TextBox)(rptr.Items[0]).FindControl("Custom4")).Text;
                //p.Custom5 = ((TextBox)(rptr.Items[0]).FindControl("Custom5")).Text;

                p.AvatarID = FormatHelper.SafeToInt(((System.Web.UI.HtmlControls.HtmlInputText)rptr.Items[0].FindControl("AvatarID")).Value);

                var registeringMasterAccount = true;
                if (RegisteringFamily.Text != "0")
                {
                    registeringMasterAccount = false;
                    p.MasterAcctPID          = int.Parse(MasterPID.Text);
                }
                if (p.IsValid(BusinessRulesValidationMode.INSERT))
                {
                    p.Insert();

                    var prog = Programs.FetchObject(p.ProgID);
                    var list = new List <Badge>();
                    if (prog.RegistrationBadgeID != 0)
                    {
                        AwardPoints.AwardBadgeToPatron(prog.RegistrationBadgeID, p, ref list);

                        #region replaced by call above

                        //    var now = DateTime.Now;
                        //    var pb = new PatronBadges { BadgeID = prog.RegistrationBadgeID, DateEarned = now, PID = p.PID };
                        //    pb.Insert();

                        //    var EarnedBadge = Badge.GetBadge(prog.RegistrationBadgeID);

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

                        //    //if badge generates prize, then generate the prize
                        //    if (EarnedBadge.IncludesPhysicalPrizeFlag)
                        //    {
                        //        var ppp = new DAL.PatronPrizes
                        //        {
                        //            PID = p.PID,
                        //            PrizeSource = 1,
                        //            PrizeName = EarnedBadge.PhysicalPrizeName,
                        //            RedeemedFlag = false,
                        //            AddedUser = p.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(p.ProgID, p.ProgID);

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

                        #endregion
                    }
                    AwardPoints.AwardBadgeToPatronViaMatchingAwards(p, ref list);

                    var sBadges = "";
                    sBadges = list.Aggregate(sBadges, (current, b) => current + "|" + b.BID.ToString());
                    if (p.IsMasterAccount && sBadges.Length > 0)
                    {
                        GoToUrl = ("~/BadgeAward.aspx?b=" + sBadges);                                           // if family account and is master, and has badges, rememebr to show them
                    }
                    if (!p.IsMasterAccount && p.MasterAcctPID == 0 && sBadges.Length > 0)
                    {
                        GoToUrl = ("~/BadgeAward.aspx?b=" + sBadges);                                                                   // if not family master or not family at all and badges, rememebr to show ...
                    }
                    if (registeringMasterAccount)
                    {
                        MasterPID.Text              = p.PID.ToString();
                        Session["PatronLoggedIn"]   = true;
                        Session["Patron"]           = p;
                        Session["ProgramID"]        = p.ProgID;
                        Session["PatronProgramID"]  = p.ProgID;
                        Session["CurrentProgramID"] = p.ProgID;
                    }
                }
                else
                {
                    string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                    foreach (BusinessRulesValidationMessage m in p.ErrorCodes)
                    {
                        message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                    }
                    message       = string.Format("{0}</ul>", message);
                    lblError.Text = message;
                    return(false);
                }
            }
            catch (Exception ex)
            {
                lblError.Text = String.Format(SRPResources.ApplicationError1, ex.Message);

                return(false);
            }
            return(true);
        }
        public void ProcessTheWin()
        {
            var mg      = DAL.Minigame.FetchObject(int.Parse(MGID.Text));
            var pa      = new AwardPoints(int.Parse(PID.Text));
            var sBadges = pa.AwardPointsToPatron(mg.NumberPoints, PointAwardReason.MiniGameCompletion, mg.MGID);

            if (sBadges.Length > 0)
            {
                Response.Redirect("~/BadgeAward.aspx?b=" + sBadges);
            }


            //var mg = DAL.Minigame.FetchObject(int.Parse(MGID.Text));
            //var patron = (Patron)Patron.FetchObject(int.Parse(PID.Text));
            //var pgm = Programs.FetchObject(patron.ProgID);

            //var StartingPoints = PatronPoints.GetTotalPatronPoints(patron.PID);
            //var EndingPoints = StartingPoints;
            //var EarnedBadges = new List<Badge>();
            //Badge EarnedBadge;

            //// 1 - log points to patron activity (mg.NumberPoints)
            //var now = DateTime.Now;
            //var pp = new PatronPoints
            //{
            //    PID = patron.PID,
            //    NumPoints = mg.NumberPoints,
            //    AwardDate = now,
            //    AwardReasonCd = (int)PointAwardReason.MiniGameCompletion,
            //    AwardReason = PatronPoints.PointAwardReasonCdToDescription(PointAwardReason.MiniGameCompletion),
            //    BadgeAwardedFlag = false,
            //    isBookList = false,
            //    isEvent = false,
            //    isGame = false,
            //    isGameLevelActivity = true,
            //    GameLevelActivityID = mg.MGID,
            //    isReading = false,
            //    LogID = 0
            //};
            //pp.Insert();

            //if (mg.AwardedBadgeID > 0)
            //{
            //    var pbds = PatronBadges.GetAll(patron.PID);
            //    var a = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == mg.AwardedBadgeID);

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

            //    if (newTable.Rows.Count == 0)
            //    {
            //        var pb = new PatronBadges { BadgeID = mg.AwardedBadgeID, DateEarned = now, PID = patron.PID };
            //        pb.Insert();

            //        EarnedBadge = Badge.GetBadge(mg.AwardedBadgeID);
            //        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();
            //        }

            //        pp.BadgeAwardedFlag = true;
            //        pp.BadgeID = mg.AwardedBadgeID;
            //        pp.Update();
            //    }


            //}
            //EndingPoints = PatronPoints.GetTotalPatronPoints(patron.PID);
            //EarnedBadge = null;
            //EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref EarnedBadges);
            //if (EarnedBadge != null)
            //{
            //    // 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 (EarnedBadges.Count > 0)
            //{
            //    //Display Badges Awards messages
            //    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());
            //    //Server.Transfer("~/BadgeAward.aspx?b=" + badges);
            //    Response.Redirect("~/BadgeAward.aspx?b=" + badges);

            //}
        }