Пример #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);
        }
        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);
        }