private void btnSubmit_Click(object sender, EventArgs e) { int i, profileID; CheckBox cbox; ProfileMember pm; Profile profile; Lookup luSource, luStatus; string userID = CurrentUser.Identity.Name; // // Lookup the profile source. // luSource = new Lookup(Int32.Parse(SourceLUIDSetting)); luStatus = new Lookup(Int32.Parse(StatusLUIDSetting)); if (luSource.LookupID == -1 || luStatus.LookupID == -1) { } // // Walk each of the controls found and determine if we need to // take any action for the value of that control. // for (i = 0; i < phProfiles.Controls.Count; i++) { // // If the control is not a checkbox or radio button then // ignore it. // if (phProfiles.Controls[i].GetType() != typeof(CheckBox) && phProfiles.Controls[i].GetType() != typeof(RadioButton)) { continue; } // // Pretend the control is a checkbox, if it is a radio button // it will cast fine since the radio button inherits from a // check box. // cbox = (CheckBox)phProfiles.Controls[i]; profileID = Int32.Parse(cbox.ID); profile = new Profile(profileID); // // If this control is turned on and it is not a "none of the above" // setting, then we need to take action. // if (cbox.Checked == true && profile.ProfileID != -1) { // // Verify this person is not already in the profile. // pm = new ProfileMember(profileID, ArenaContext.Current.Person); if (pm.ProfileID == -1) { // // The person needs to be added to the profile, generate all // the standard information. // pm = new ProfileMember(); pm.ProfileID = profileID; pm.PersonID = ArenaContext.Current.Person.PersonID; pm.Source = luSource; pm.Status = luStatus; pm.DatePending = DateTime.Now; pm.Save(userID); // // If the profile is a serving tag then we need to generate // a little bit more information. // if (profile.ProfileType == ProfileType.Serving) { ServingProfile sProfile = new ServingProfile(profile.ProfileID); ServingProfileMember sMember = new ServingProfileMember(pm.ProfileID, pm.PersonID); sMember.HoursPerWeek = sProfile.DefaultHoursPerWeek; sMember.Save(); } } } } // // Redirect browser back to originating page. // Response.Redirect(iRedirect.Value); }
/// <summary> /// Add a placemark object to a profile. If the placemark is a PersonPlacemark /// then the associated person record is used. If it is a FamilyPlacemark then /// all the members of the family are used. Otherwise the placemark is ignored. /// This method only adds individuals who are not already a member of the tag. /// </summary> /// <param name="placemark">The placemark to add to the profile.</param> /// <param name="profile">The profile to add the members to.</param> private void AddPlacemarkToProfile(Placemark placemark, Profile profile) { List <Person> people = new List <Person>(); // // Convert the placemark into a list of people that should be added. // if (placemark.GetType() == typeof(PersonPlacemark)) { people.Add(((PersonPlacemark)placemark).GetPerson()); } else if (placemark.GetType() == typeof(FamilyPlacemark)) { foreach (Person p in ((FamilyPlacemark)placemark).GetFamily().FamilyMembersActive) { people.Add(p); } } // // For each person found, verify that they should be added and then // add them if they are not already in the profile. // foreach (Person p in people) { ProfileMember pm; // // Verify they are an adult if the user wants only adults. // if (profileOnlyAdults.Checked == true) { FamilyMember fm = new FamilyMember(p.FamilyId, p.PersonID); if (!fm.FamilyRole.Guid.ToString().Equals("e410e1a6-8715-4bfb-bf03-1cd18051f815", StringComparison.InvariantCultureIgnoreCase)) { continue; } } // // Verify they are not already in the profile. // pm = new ProfileMember(profile.ProfileID, p); if (pm.ProfileID == -1) { pm = new ProfileMember(); // // Add them to the profile. // pm.ProfileID = profile.ProfileID; pm.PersonID = p.PersonID; pm.Source = ProfileSource; pm.Status = ProfileStatus; pm.DateActive = DateTime.Now; pm.Save(ArenaContext.Current.User.Identity.Name); // // If this is a serving profile, we need a little more information. // if (profile.ProfileType == Enums.ProfileType.Serving) { ServingProfile sp = new ServingProfile(profile.ProfileID); ServingProfileMember spm = new ServingProfileMember(pm.ProfileID, pm.PersonID); spm.HoursPerWeek = sp.DefaultHoursPerWeek; spm.Save(ArenaContext.Current.User.Identity.Name); } } } }
private void CreateAccount() { Arena.Security.Login login; string loginID; if (CustomLoginSetting == true) { // Ensure that login ID is unique loginID = tbLoginID.Text; login = new Arena.Security.Login(loginID); if (login.PersonID != -1) { int loginCount = 0; loginID = tbFirstName.Text.Substring(0, 1).ToLower() + tbLastName.Text.Trim().ToLower(); if (loginID != loginID.ToLower()) { login = new Arena.Security.Login(loginID); } while (login.PersonID != -1) { loginCount++; login = new Arena.Security.Login(loginID + loginCount.ToString()); } lblMessage.Text = "The Desired Login ID you selected is already in use in our system. Please select a different Login ID. Suggestion: <b>" + loginID + loginCount.ToString() + "</b>"; pnlMessage.Visible = true; lblMessage.Visible = true; return; } } else { Int32 loginCount = 0; // // Construct a login Id that can be used. // do { if (loginCount == 0) { loginID = tbFirstName.Text + " " + tbLastName.Text; } else { loginID = tbFirstName.Text + " " + tbLastName.Text + loginCount.ToString(); } loginID = loginID.ToLower(); login = new Arena.Security.Login(loginID); loginCount++; } while (login.PersonID != -1); } Lookup memberStatus; try { memberStatus = new Lookup(Int32.Parse(MemberStatusIDSetting)); if (memberStatus.LookupID == -1) { throw new ModuleException(CurrentPortalPage, CurrentModule, "Member Status setting must be a valid Member Status Lookup value."); } } catch (System.Exception ex) { throw new ModuleException(CurrentPortalPage, CurrentModule, "Member Status setting must be a valid Member Status Lookup value.", ex); } int organizationID = CurrentPortal.OrganizationID; string userID = CurrentUser.Identity.Name; if (userID == string.Empty) { userID = "NewAccount.ascx"; } Person person = new Person(); person.RecordStatus = RecordStatus.Pending; person.MemberStatus = memberStatus; if (CampusSetting != string.Empty) { try { person.Campus = new Arena.Organization.Campus(Int32.Parse(CampusSetting)); } catch { person.Campus = null; } } person.FirstName = tbFirstName.Text.Trim(); person.LastName = tbLastName.Text.Trim(); if (tbBirthDate.Text.Trim() != string.Empty) { try { person.BirthDate = DateTime.Parse(tbBirthDate.Text); } catch { } } if (ddlMaritalStatus.SelectedValue != string.Empty) { person.MaritalStatus = new Lookup(Int32.Parse(ddlMaritalStatus.SelectedValue)); } if (ddlGender.SelectedValue != string.Empty) { try { person.Gender = (Gender)Enum.Parse(typeof(Gender), ddlGender.SelectedValue); } catch { } } PersonAddress personAddress = new PersonAddress(); personAddress.Address = new Address( tbStreetAddress.Text.Trim(), string.Empty, tbCity.Text.Trim(), ddlState.SelectedValue, tbZipCode.Text.Trim(), false); personAddress.AddressType = new Lookup(SystemLookup.AddressType_Home); personAddress.Primary = true; person.Addresses.Add(personAddress); PersonPhone phone = new PersonPhone(); phone.Number = tbHomePhone.PhoneNumber.Trim(); phone.PhoneType = new Lookup(SystemLookup.PhoneType_Home); person.Phones.Add(phone); if (tbWorkPhone.PhoneNumber.Trim() != string.Empty) { phone = new PersonPhone(); phone.Number = tbWorkPhone.PhoneNumber.Trim(); phone.Extension = tbWorkPhone.Extension; phone.PhoneType = new Lookup(SystemLookup.PhoneType_Business); person.Phones.Add(phone); } if (tbCellPhone.PhoneNumber.Trim() != string.Empty) { phone = new PersonPhone(); phone.Number = tbCellPhone.PhoneNumber.Trim(); phone.PhoneType = new Lookup(SystemLookup.PhoneType_Cell); phone.SMSEnabled = cbSMS.Checked; person.Phones.Add(phone); } if (tbEmail.Text.Trim() != string.Empty) { PersonEmail personEmail = new PersonEmail(); personEmail.Active = true; personEmail.Email = tbEmail.Text.Trim(); person.Emails.Add(personEmail); } person.Save(organizationID, userID, false); person.SaveAddresses(organizationID, userID); person.SavePhones(organizationID, userID); person.SaveEmails(organizationID, userID); Family family = new Family(); family.OrganizationID = organizationID; family.FamilyName = tbLastName.Text.Trim() + " Family"; family.Save(userID); FamilyMember fm = new FamilyMember(family.FamilyID, person.PersonID); fm.FamilyID = family.FamilyID; fm.FamilyRole = new Lookup(SystemLookup.FamilyRole_Adult); fm.Save(userID); Arena.Security.Login personLogin = new Arena.Security.Login(); personLogin.PersonID = person.PersonID; personLogin.LoginID = loginID; personLogin.Password = tbPassword.Text.Trim(); personLogin.Active = true; personLogin.Save(userID); // Use security system to set the UserID within a client-side Cookie FormsAuthentication.SetAuthCookie(personLogin.LoginID, false); Response.Cookies["portalroles"].Value = string.Empty; if (ProfileIDSetting != string.Empty) { int profileID = -1; int sourceLUID = -1; int statusLUID = -1; try { if (ProfileIDSetting.Contains("|")) { profileID = Int32.Parse(ProfileIDSetting.Split('|')[1]); } else { profileID = Int32.Parse(ProfileIDSetting); } sourceLUID = Int32.Parse(SourceLUIDSetting); statusLUID = Int32.Parse(StatusLUIDSetting); } catch (System.Exception ex) { throw new ModuleException(CurrentPortalPage, CurrentModule, "If using a ProfileID setting for the NewAccount module, " + "then a valid numeric 'ProfileID', 'SourceLUID', and 'StatusLUID' setting must all be used!", ex); } Profile profile = new Profile(profileID); Lookup sourceLu = new Lookup(sourceLUID); Lookup statusLu = new Lookup(statusLUID); if (profile.ProfileID != -1 && sourceLu.LookupID != -1 && statusLu.LookupID != -1) { ProfileMember profileMember = new ProfileMember(); profileMember.ProfileID = profile.ProfileID; profileMember.PersonID = person.PersonID; profileMember.Source = sourceLu; profileMember.Status = statusLu; profileMember.DatePending = DateTime.Now; profileMember.Save(userID); if (profile.ProfileType == ProfileType.Serving) { ServingProfile sProfile = new ServingProfile(profile.ProfileID); ServingProfileMember sMember = new ServingProfileMember(profileMember.ProfileID, profileMember.PersonID); sMember.HoursPerWeek = sProfile.DefaultHoursPerWeek; sMember.Save(); } } else { throw new ModuleException(CurrentPortalPage, CurrentModule, "'ProfileID', 'SourceLUID', and 'StatusLUID' must all be valid IDs"); } } // // If we are letting the user pick their own login ID then just redirect // the browser back to the originating page. Otherwise put up some text to // tell the user what their new login ID is. // if (CustomLoginSetting == true) { Response.Redirect(iRedirect.Value); } else { pnlCreateAccount.Visible = false; lbLoginCreated.Text = "Your account has been created. Your login ID is \"" + loginID + "\".<BR /><BR />You may use this login ID the next time you visit this site.<BR />"; pnlLoginCreated.Visible = true; } }