void modalAddPerson_SaveClick(object sender, EventArgs e) { if (!string.IsNullOrWhiteSpace(acPerson.Value)) { int personId = int.MinValue; if (int.TryParse(acPerson.Value, out personId)) { int?roleId = grpRole.GroupRoleId; if (roleId.HasValue) { using (new UnitOfWorkScope()) { var memberService = new GroupMemberService(); var group = memberService.Queryable() .Where(m => m.PersonId == Person.Id && m.GroupRole.Guid == ownerRoleGuid ) .Select(m => m.Group) .FirstOrDefault(); if (group != null) { var groupMember = memberService.Queryable() .Where(m => m.GroupId == group.Id && m.PersonId == personId && m.GroupRoleId == roleId.Value) .FirstOrDefault(); if (groupMember == null) { groupMember = new GroupMember(); groupMember.GroupId = group.Id; groupMember.PersonId = personId; groupMember.GroupRoleId = roleId.Value; memberService.Add(groupMember, CurrentPersonId); } memberService.Save(groupMember, CurrentPersonId); if (IsKnownRelationships) { var inverseGroupMember = memberService.GetInverseRelationship( groupMember, bool.Parse(GetAttributeValue("CreateGroup")), CurrentPersonId); if (inverseGroupMember != null) { memberService.Save(inverseGroupMember, CurrentPersonId); } } } } } } } BindData(); }
/// <summary> /// Handles the Click event of the DeleteGroupMember control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs" /> instance containing the event data.</param> protected void DeleteGroupMember_Click(object sender, Rock.Web.UI.Controls.RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { GroupMemberService groupMemberService = new GroupMemberService(); GroupMember groupMember = groupMemberService.Get(e.RowKeyId); if (groupMember != null) { string errorMessage; if (!groupMemberService.CanDelete(groupMember, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } int groupId = groupMember.GroupId; groupMemberService.Delete(groupMember, CurrentPersonId); groupMemberService.Save(groupMember, CurrentPersonId); Group group = new GroupService().Get(groupId); if (group.IsSecurityRole) { // person removed from SecurityRole, Flush Rock.Security.Authorization.Flush(); } } }); BindGroupMembersGrid(); }
void rGroupMembers_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e) { int groupMemberId = int.MinValue; if (int.TryParse(e.CommandArgument.ToString(), out groupMemberId)) { var service = new GroupMemberService(); var groupMember = service.Get(groupMemberId); if (groupMember != null) { if (e.CommandName == "EditRole") { ShowModal(groupMember.Person, groupMember.GroupRoleId); } else if (e.CommandName == "RemoveRole") { if (IsKnownRelationships) { var inverseGroupMember = service.GetInverseRelationship(groupMember, false, CurrentPersonId); if (inverseGroupMember != null) { service.Delete(inverseGroupMember, CurrentPersonId); } } service.Delete(groupMember, CurrentPersonId); service.Save(groupMember, CurrentPersonId); BindData(); } } } }
/// <summary> /// Adds the group member. /// </summary> /// <param name="familyGroup">The family group.</param> /// <param name="person">The person.</param> /// <returns></returns> protected GroupMember AddGroupMember(int familyGroupId, Person person) { GroupMember groupMember = new GroupMember().Clone(false); GroupMemberService groupMemberService = new GroupMemberService(); groupMember.IsSystem = false; groupMember.GroupId = familyGroupId; groupMember.PersonId = person.Id; if (person.Age >= 18) { groupMember.GroupRoleId = new GroupTypeRoleService().Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT)).Id; } else { groupMember.GroupRoleId = new GroupTypeRoleService().Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD)).Id; } Rock.Data.RockTransactionScope.WrapTransaction(() => { groupMemberService.Add(groupMember, CurrentPersonId); groupMemberService.Save(groupMember, CurrentPersonId); }); return(groupMember); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); try { string groupMemberKey = PageParameter("gm"); if (string.IsNullOrWhiteSpace(groupMemberKey)) { ShowError("Missing Parameter Value"); } else { var groupMemberService = new GroupMemberService(); var groupMember = groupMemberService.GetByUrlEncodedKey(PageParameter("gm")); if (groupMember == null) { ShowError(); } else { groupMember.GroupMemberStatus = GroupMemberStatus.Active; groupMemberService.Save(groupMember, CurrentPersonId); nbMessage.NotificationBoxType = NotificationBoxType.Success; nbMessage.Title = "Success"; nbMessage.Text = GetAttributeValue("SuccessMessage"); } } } catch (SystemException ex) { ShowError(ex.Message); } }
/// <summary> /// Handles the RowCommand event of the grdPersonSearchResults control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="GridViewCommandEventArgs"/> instance containing the event data.</param> protected void rGridPersonResults_AddExistingPerson(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Add") { GroupMemberService groupMemberService = new GroupMemberService(); int index = int.Parse(e.CommandArgument.ToString()); int personId = int.Parse(rGridPersonResults.DataKeys[index].Value.ToString()); var family = CurrentCheckInState.CheckIn.Families.Where(f => f.Selected).FirstOrDefault(); if (family != null) { var checkInPerson = new CheckInPerson(); checkInPerson.Person = new PersonService().Get(personId).Clone(false); var isPersonInFamily = family.People.Any(p => p.Person.Id == checkInPerson.Person.Id); if (!isPersonInFamily) { if (personVisitorType.Value != "Visitor") { var groupMember = groupMemberService.GetByPersonId(personId).FirstOrDefault(); groupMember.GroupId = family.Group.Id; Rock.Data.RockTransactionScope.WrapTransaction(() => { groupMemberService.Save(groupMember, CurrentPersonId); }); checkInPerson.FamilyMember = true; hfSelectedPerson.Value += personId + ","; } else { AddVisitorGroupMemberRoles(family, personId); checkInPerson.FamilyMember = false; hfSelectedVisitor.Value += personId + ","; } checkInPerson.Selected = true; family.People.Add(checkInPerson); ProcessFamily(); } mpeAddPerson.Hide(); } else { string errorMsg = "<ul><li>You have to pick a family to add this person to.</li></ul>"; maWarning.Show(errorMsg, Rock.Web.UI.Controls.ModalAlertType.Warning); } } else { mpeAddPerson.Show(); BindPersonGrid(); } }
void lb_Click(object sender, EventArgs e) { if (CurrentPersonId.HasValue) { LinkButton lb = sender as LinkButton; if (lb != null) { int groupId = 0; if (Int32.TryParse(lb.Attributes["group"], out groupId)) { int roleId = 0; if (!Int32.TryParse(AttributeValue("GroupRole"), out roleId)) { roleId = 0; } var group = groupService.Get(groupId); if (group != null && group.AttributeValues.ContainsKey(_videoAttributeKey)) { hfVideoUrl.Value = group.AttributeValues[_videoAttributeKey][0].Value; GroupMemberService memberService = new GroupMemberService(); var groupMember = memberService.GetByGroupIdAndPersonIdAndGroupRoleId( groupId, CurrentPersonId.Value, roleId); if (groupMember == null) { groupMember = new GroupMember(); groupMember.GroupId = groupId; groupMember.PersonId = CurrentPersonId.Value; groupMember.GroupRoleId = roleId; memberService.Add(groupMember, CurrentPersonId); memberService.Save(groupMember, CurrentPersonId); } HtmlGenericControl li = lb.Parent as HtmlGenericControl; if (li != null) { li.RemoveCssClass("not-viewed"); li.AddCssClass("viewed"); } } } } } }
/// <summary> /// Handles the Delete event of the gList control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param> protected void gList_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { var groupMemberService = new GroupMemberService(); int groupMemberId = (int)e.RowKeyValue; GroupMember groupMember = groupMemberService.Get(groupMemberId); if (groupMember != null) { // check if person can be removed from the Group and also check if person can be removed from all the person assigned competencies string errorMessage; if (!groupMemberService.CanDelete(groupMember, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } var competencyPersonService = new ResidencyService <CompetencyPerson>(); var personCompetencyList = competencyPersonService.Queryable().Where(a => a.PersonId.Equals(groupMember.PersonId)); foreach (var item in personCompetencyList) { if (!competencyPersonService.CanDelete(item, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } } // if you made it this far, delete all person's assigned competencies, and finally delete from Group foreach (var item in personCompetencyList) { competencyPersonService.Delete(item, CurrentPersonId); competencyPersonService.Save(item, CurrentPersonId); } groupMemberService.Delete(groupMember, CurrentPersonId); groupMemberService.Save(groupMember, CurrentPersonId); } }); BindGrid(); }
/// <summary> /// Handles the Click event of the btnGive control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void btnGive_Click(object sender, EventArgs e) { Person person = FindPerson(); using (new UnitOfWorkScope()) { RockTransactionScope.WrapTransaction(() => { var groupLocationService = new GroupLocationService(); var groupMemberService = new GroupMemberService(); var phoneService = new PhoneNumberService(); var locationService = new LocationService(); var groupService = new GroupService(); GroupLocation groupLocation; Location homeAddress; Group familyGroup; var homeLocationType = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.LOCATION_TYPE_HOME); var addressList = locationService.Queryable().Where(l => l.Street1 == txtStreet.Text && l.City == txtCity.Text && l.State == ddlState.SelectedValue && l.Zip == txtZip.Text && l.LocationTypeValueId == homeLocationType.Id).ToList(); if (!addressList.Any()) { homeAddress = new Location(); locationService.Add(homeAddress, person.Id); } else { homeAddress = addressList.FirstOrDefault(); } homeAddress.Street1 = txtStreet.Text ?? homeAddress.Street1; homeAddress.City = txtCity.Text ?? homeAddress.City; homeAddress.State = ddlState.SelectedValue ?? homeAddress.State; homeAddress.Zip = txtZip.Text ?? homeAddress.Zip; homeAddress.IsActive = true; homeAddress.IsLocation = true; homeAddress.Country = "US"; homeAddress.LocationTypeValueId = homeLocationType.Id; locationService.Save(homeAddress, person.Id); GroupType familyGroupType = new GroupTypeService().Get(new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY)); var familyGroupList = groupMemberService.Queryable().Where(g => g.PersonId == person.Id && g.Group.GroupType.Guid == familyGroupType.Guid).Select(g => g.Group).ToList(); if (!familyGroupList.Any()) { familyGroup = new Group(); familyGroup.IsActive = true; familyGroup.IsSystem = false; familyGroup.IsSecurityRole = false; familyGroup.Name = "The " + txtLastName.Text + " Family"; familyGroup.GroupTypeId = familyGroupType.Id; groupService.Add(familyGroup, person.Id); groupService.Save(familyGroup, person.Id); var familyMember = new GroupMember(); familyMember.IsSystem = false; familyMember.GroupId = familyGroup.Id; familyMember.PersonId = person.Id; familyMember.GroupRoleId = new GroupRoleService().Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT)).Id; groupMemberService.Add(familyMember, person.Id); groupMemberService.Save(familyMember, person.Id); } else { familyGroup = familyGroupList.FirstOrDefault(); } var groupLocationList = groupLocationService.Queryable().Where(g => g.GroupLocationTypeValueId == familyGroupType.Id && g.GroupId == familyGroup.Id).ToList(); if (!groupLocationList.Any()) { groupLocation = new GroupLocation(); groupLocation.GroupId = familyGroup.Id; groupLocation.LocationId = homeAddress.Id; groupLocation.IsMailing = true; groupLocation.IsLocation = true; groupLocation.GroupLocationTypeValueId = homeLocationType.Id; groupLocationService.Add(groupLocation, person.Id); groupLocationService.Save(groupLocation, person.Id); } else { groupLocation = groupLocationList.FirstOrDefault(); } groupLocation.LocationId = homeAddress.Id; groupLocationService.Save(groupLocation, person.Id); var homePhoneType = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_HOME); string phoneNumeric = txtPhone.Text.AsNumeric(); if (!phoneService.Queryable().Where(n => n.PersonId == person.Id && n.NumberTypeValueId == homePhoneType.Id && n.Number == phoneNumeric).Any()) { var homePhone = new PhoneNumber(); homePhone.Number = phoneNumeric; homePhone.PersonId = person.Id; homePhone.IsSystem = false; homePhone.IsMessagingEnabled = false; homePhone.IsUnlisted = false; homePhone.NumberTypeValueId = homePhoneType.Id; phoneService.Add(homePhone, person.Id); phoneService.Save(homePhone, person.Id); } }); } var amountList = (Dictionary <FinancialAccount, Decimal>)Session["CachedAmounts"]; var profileId = (int)Session["CachedProfileId"]; Location giftLocation = new Location(); var configValues = (Dictionary <string, object>)Session["CachedMergeFields"]; configValues.Add("Date", DateTimeOffset.Now.ToString("MM/dd/yyyy hh:mm tt")); var receiptTemplate = GetAttributeValue("ReceiptMessage"); lReceipt.Text = receiptTemplate.ResolveMergeFields(configValues); var summaryTemplate = GetAttributeValue("SummaryMessage"); string summaryMessage = summaryTemplate.ResolveMergeFields(configValues); var creditProcessorId = GetAttributeValue("CreditCardProvider"); var achProcessorId = GetAttributeValue("Checking/ACHProvider"); var gatewayService = new FinancialGatewayService(); FinancialGateway gateway; if (!string.IsNullOrEmpty(txtCreditCard.Text) && !string.IsNullOrWhiteSpace(creditProcessorId)) { int creditId = Convert.ToInt32(creditProcessorId); gateway = new FinancialGatewayService().Get(creditId); } else if (!string.IsNullOrEmpty(txtAccountNumber.Text) && !string.IsNullOrWhiteSpace(achProcessorId)) { int achId = Convert.ToInt32(achProcessorId); gateway = new FinancialGatewayService().Get(achId); } else { gateway = gatewayService.Queryable().FirstOrDefault(); } // #TODO test card through gateway if (btnFrequency.SelectedIndex > -1 && btnFrequency.SelectedValueAsInt() != DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.TRANSACTION_FREQUENCY_TYPE_ONE_TIME).Id) { using (new UnitOfWorkScope()) { RockTransactionScope.WrapTransaction(() => { var scheduledTransactionDetailService = new FinancialScheduledTransactionDetailService(); var scheduledTransactionService = new FinancialScheduledTransactionService(); FinancialScheduledTransaction scheduledTransaction; var detailList = amountList.ToList(); if (profileId > 0) { scheduledTransaction = scheduledTransactionService.Get(profileId); } else { scheduledTransaction = new FinancialScheduledTransaction(); scheduledTransactionService.Add(scheduledTransaction, person.Id); } DateTime startDate = (DateTime)dtpStartDate.SelectedDate; if (startDate != null) { scheduledTransaction.StartDate = startDate; } scheduledTransaction.TransactionFrequencyValueId = (int)btnFrequency.SelectedValueAsInt(); scheduledTransaction.AuthorizedPersonId = person.Id; scheduledTransaction.IsActive = true; if (!string.IsNullOrEmpty(txtCreditCard.Text)) { scheduledTransaction.CardReminderDate = mypExpiration.SelectedDate; } if (chkLimitGifts.Checked && !string.IsNullOrWhiteSpace(txtLimitNumber.Text)) { scheduledTransaction.NumberOfPayments = Convert.ToInt32(txtLimitNumber.Text); } foreach (var detail in amountList.ToList()) { var scheduledTransactionDetail = new FinancialScheduledTransactionDetail(); scheduledTransactionDetail.AccountId = detail.Key.Id; scheduledTransactionDetail.Amount = detail.Value; scheduledTransactionDetail.ScheduledTransactionId = scheduledTransaction.Id; scheduledTransactionDetailService.Add(scheduledTransactionDetail, person.Id); scheduledTransactionDetailService.Save(scheduledTransactionDetail, person.Id); } // implement gateway charge() scheduledTransactionService.Save(scheduledTransaction, person.Id); }); } } else { using (new UnitOfWorkScope()) { RockTransactionScope.WrapTransaction(() => { var transactionService = new FinancialTransactionService(); var tdService = new FinancialTransactionDetailService(); var transaction = new FinancialTransaction(); var detailList = amountList.ToList(); transaction.Summary = summaryMessage; transaction.Amount = detailList.Sum(d => d.Value); transaction.TransactionTypeValueId = DefinedValueCache.Read(Rock.SystemGuid.DefinedValue.TRANSACTION_TYPE_CONTRIBUTION).Id; transaction.TransactionDateTime = DateTimeOffset.Now.DateTime; transaction.AuthorizedPersonId = person.Id; transactionService.Add(transaction, person.Id); foreach (var detail in detailList) { var td = new FinancialTransactionDetail(); td.TransactionId = transaction.Id; td.AccountId = detail.Key.Id; td.Amount = detail.Value; td.TransactionId = transaction.Id; tdService.Add(td, person.Id); tdService.Save(td, person.Id); } // #TODO implement gateway.charge() transactionService.Save(transaction, person.Id); }); } } Session["CachedMergeFields"] = configValues; pnlConfirm.Visible = false; pnlComplete.Visible = true; pnlContribution.Update(); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { // confirmation was disabled by btnSave on client-side. So if returning without a redirect, // it should be enabled. If returning with a redirect, the control won't be updated to reflect // confirmation being enabled, so it's ok to enable it here confirmExit.Enabled = true; if (Page.IsValid) { confirmExit.Enabled = true; using (new UnitOfWorkScope()) { var familyService = new GroupService(); var familyMemberService = new GroupMemberService(); var personService = new PersonService(); // SAVE FAMILY _family = familyService.Get(_family.Id); _family.Name = tbFamilyName.Text; _family.CampusId = cpCampus.SelectedValueAsInt(); var familyGroupTypeId = _family.GroupTypeId; familyService.Save(_family, CurrentPersonId); // SAVE FAMILY MEMBERS int?recordStatusValueID = ddlRecordStatus.SelectedValueAsInt(); int?reasonValueId = ddlReason.SelectedValueAsInt(); var newFamilies = new List <Group>(); foreach (var familyMember in FamilyMembers) { var role = familyRoles.Where(r => r.Guid.Equals(familyMember.RoleGuid)).FirstOrDefault(); if (role == null) { role = familyRoles.FirstOrDefault(); } // People added to family (new or from other family) if (!familyMember.ExistingFamilyMember) { var groupMember = new GroupMember(); if (familyMember.Id == -1) { // added new person groupMember.Person = new Person(); groupMember.Person.GivenName = familyMember.FirstName; groupMember.Person.LastName = familyMember.LastName; groupMember.Person.Gender = familyMember.Gender; groupMember.Person.BirthDate = familyMember.BirthDate; } else { // added from other family groupMember.Person = personService.Get(familyMember.Id); } groupMember.Person.RecordStatusValueId = recordStatusValueID; groupMember.Person.RecordStatusReasonValueId = reasonValueId; groupMember.GroupId = _family.Id; if (role != null) { groupMember.GroupRoleId = role.Id; } if (groupMember.Person != null) { familyMemberService.Add(groupMember, CurrentPersonId); familyMemberService.Save(groupMember, CurrentPersonId); } } else { // existing family members var groupMember = familyMemberService.Queryable().Where(m => m.PersonId == familyMember.Id && m.Group.GroupTypeId == familyGroupTypeId && m.GroupId == _family.Id).FirstOrDefault(); if (groupMember != null) { if (familyMember.Removed) { // Family member was removed and should be created in their own new family var newFamily = new Group(); newFamily.Name = familyMember.LastName + " Family"; newFamily.GroupTypeId = familyGroupTypeId; newFamily.CampusId = _family.CampusId; familyService.Add(newFamily, CurrentPersonId); familyService.Save(newFamily, CurrentPersonId); groupMember.Group = newFamily; familyMemberService.Save(groupMember, CurrentPersonId); newFamilies.Add(newFamily); } else { // Existing member was not remvoved if (role != null) { groupMember.GroupRoleId = role.Id; groupMember.Person.RecordStatusValueId = recordStatusValueID; groupMember.Person.RecordStatusReasonValueId = reasonValueId; familyMemberService.Save(groupMember, CurrentPersonId); } } } } // Remove anyone that was moved from another family if (familyMember.RemoveFromOtherFamilies) { var otherFamilies = familyMemberService.Queryable() .Where(m => m.PersonId == familyMember.Id && m.Group.GroupTypeId == familyGroupTypeId && m.GroupId != _family.Id) .ToList(); foreach (var otherFamilyMember in otherFamilies) { var fm = familyMemberService.Get(otherFamilyMember.Id); familyMemberService.Delete(fm, CurrentPersonId); familyMemberService.Save(fm, CurrentPersonId); var f = familyService.Queryable() .Where(g => g.Id == otherFamilyMember.GroupId && !g.Members.Any()) .FirstOrDefault(); if (f != null) { familyService.Delete(f, CurrentPersonId); familyService.Save(f, CurrentPersonId); } } } } // SAVE LOCATIONS var groupLocationService = new GroupLocationService(); // delete any group locations that were removed var remainingLocationIds = FamilyAddresses.Where(a => a.Id > 0).Select(a => a.Id).ToList(); foreach (var removedLocation in groupLocationService.Queryable() .Where(l => l.GroupId == _family.Id && !remainingLocationIds.Contains(l.Id))) { groupLocationService.Delete(removedLocation, CurrentPersonId); groupLocationService.Save(removedLocation, CurrentPersonId); } foreach (var familyAddress in FamilyAddresses) { Location updatedAddress = null; if (familyAddress.LocationIsDirty) { updatedAddress = new LocationService().Get( familyAddress.Street1, familyAddress.Street2, familyAddress.City, familyAddress.State, familyAddress.Zip); } GroupLocation groupLocation = null; if (familyAddress.Id > 0) { groupLocation = groupLocationService.Get(familyAddress.Id); } if (groupLocation == null) { groupLocation = new GroupLocation(); groupLocation.GroupId = _family.Id; groupLocationService.Add(groupLocation, CurrentPersonId); } groupLocation.GroupLocationTypeValueId = familyAddress.LocationTypeId; groupLocation.IsMailing = familyAddress.IsMailing; groupLocation.IsLocation = familyAddress.IsLocation; if (updatedAddress != null) { groupLocation.Location = updatedAddress; } groupLocationService.Save(groupLocation, CurrentPersonId); // Add the same locations to any new families created by removing an existing family member if (newFamilies.Any()) { //reload grouplocation for access to child properties groupLocation = groupLocationService.Get(groupLocation.Id); foreach (var newFamily in newFamilies) { var newFamilyLocation = new GroupLocation(); newFamilyLocation.GroupId = newFamily.Id; newFamilyLocation.LocationId = groupLocation.LocationId; newFamilyLocation.GroupLocationTypeValueId = groupLocation.GroupLocationTypeValueId; newFamilyLocation.IsMailing = groupLocation.IsMailing; newFamilyLocation.IsLocation = groupLocation.IsLocation; groupLocationService.Add(newFamilyLocation, CurrentPersonId); groupLocationService.Save(newFamilyLocation, CurrentPersonId); } } } _family = familyService.Get(_family.Id); if (_family.Members.Any(m => m.PersonId == Person.Id)) { Response.Redirect(string.Format("~/Person/{0}", Person.Id), false); } else { var fm = _family.Members .Where(m => m.GroupRole.Guid.Equals(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT)) && m.Person.Gender == Gender.Male) .OrderByDescending(m => m.Person.Age) .FirstOrDefault(); if (fm == null) { fm = _family.Members .Where(m => m.GroupRole.Guid.Equals(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT))) .OrderByDescending(m => m.Person.Age) .FirstOrDefault(); } if (fm == null) { fm = _family.Members .OrderByDescending(m => m.Person.Age) .FirstOrDefault(); } if (fm != null) { Response.Redirect(string.Format("~/Person/{0}", fm.PersonId), false); } else { Response.Redirect("~", false); } } } } }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { ClearErrorMessage(); int groupMemberId = int.Parse(hfGroupMemberId.Value); GroupRole role = new GroupRoleService().Get(ddlGroupRole.SelectedValueAsInt() ?? 0); int memberCountInRole = GetGroupMembersInRoleCount(); bool roleMembershipBelowMinimum = false; bool roleMembershipAboveMax = false; GroupMemberService groupMemberService = new GroupMemberService(); GroupMember groupMember; // if adding a new group member if (groupMemberId.Equals(0)) { groupMember = new GroupMember { Id = 0 }; groupMember.GroupId = hfGroupId.ValueAsInt(); //check to see if the person is a member fo the gorup/role int?existingGroupMemberId = FindExistingGroupMemberRole(); //if so, don't add and show error message if (existingGroupMemberId != null && existingGroupMemberId > 0) { var person = new PersonService().Get((int)ppGroupMemberPerson.PersonId); nbErrorMessage.Title = string.Format("Can not add {0} to {1} role.", person.FullName, role.Name); nbErrorMessage.Text = string.Format("<br /> {0} is already a member of the {1} role for this group, and can not be added. <a href=\"/page/{2}?groupMemberId={3}\">Click here</a> to view existing membership.", person.FullName, ddlGroupRole.SelectedItem.Text, CurrentPage.Id, existingGroupMemberId ); return; } } else { //load existing group member groupMember = groupMemberService.Get(groupMemberId); } //if adding new active group member if (groupMemberId.Equals(0) && ddlGroupMemberStatus.SelectedValueAsEnum <GroupMemberStatus>() == GroupMemberStatus.Active) { // verify that active count has not exceeded the max if (role.MaxCount != null && (memberCountInRole + 1) > role.MaxCount) { roleMembershipAboveMax = true; } //check that min count has been reached if (role.MinCount != null && (memberCountInRole + 1) < role.MinCount) { roleMembershipBelowMinimum = true; } } //if existing group member changing role or status else if (groupMemberId > 0 && (groupMember.GroupRoleId != role.Id || groupMember.GroupMemberStatus != ddlGroupMemberStatus.SelectedValueAsEnum <GroupMemberStatus>()) && ddlGroupMemberStatus.SelectedValueAsEnum <GroupMemberStatus>() == GroupMemberStatus.Active) { // verify that active count has not exceeded the max if (role.MaxCount != null && (memberCountInRole + 1) > role.MaxCount) { roleMembershipAboveMax = true; } //check that min count has been reached if (role.MinCount != null && (memberCountInRole + 1) < role.MinCount) { roleMembershipBelowMinimum = true; } } // if existing member is going inactive else if (groupMemberId > 0 && groupMember.GroupMemberStatus == GroupMemberStatus.Active && ddlGroupMemberStatus.SelectedValueAsEnum <GroupMemberStatus>() != GroupMemberStatus.Active) { //check that min count has been reached if (role.MinCount != null && (memberCountInRole - 1) < role.MinCount) { roleMembershipBelowMinimum = true; } } else { //check that min count has been reached if (role.MinCount != null && memberCountInRole < role.MinCount) { roleMembershipBelowMinimum = true; } } //show error if above max.. do not proceed if (roleMembershipAboveMax) { var person = new PersonService().Get((int)ppGroupMemberPerson.PersonId); nbErrorMessage.Title = string.Format("Can not add {0} to {1} role.", person.FullName, role.Name); nbErrorMessage.Text = string.Format("<br /> {0} role is at it's maximum capacity of {1} active members.", role.Name, role.MaxCount.ToString()); return; } groupMember.PersonId = ppGroupMemberPerson.PersonId.Value; groupMember.GroupRoleId = role.Id; groupMember.GroupMemberStatus = ddlGroupMemberStatus.SelectedValueAsEnum <GroupMemberStatus>(); groupMember.LoadAttributes(); Rock.Attribute.Helper.GetEditValues(phAttributes, groupMember); if (!Page.IsValid) { return; } if (!groupMember.IsValid) { return; } RockTransactionScope.WrapTransaction(() => { if (groupMember.Id.Equals(0)) { groupMemberService.Add(groupMember, CurrentPersonId); } groupMemberService.Save(groupMember, CurrentPersonId); Rock.Attribute.Helper.SaveAttributeValues(groupMember, CurrentPersonId); }); Dictionary <string, string> qryString = new Dictionary <string, string>(); qryString["groupId"] = hfGroupId.Value; if (roleMembershipBelowMinimum) { qryString["roleBelowMin"] = roleMembershipBelowMinimum.ToString(); qryString["roleId"] = role.Id.ToString(); } Group group = new GroupService().Get(groupMember.GroupId); if (group.IsSecurityRole) { // new person added to SecurityRole, Flush Rock.Security.Authorization.Flush(); } NavigateToParentPage(qryString); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="action">The workflow action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> /// <exception cref="System.NotImplementedException"></exception> public override bool Execute(Model.WorkflowAction action, Object entity, out List <string> errorMessages) { var checkInState = GetCheckInState(entity, out errorMessages); if (checkInState != null) { DateTime startDateTime = DateTime.Now; int securityCodeLength = 3; if (!int.TryParse(GetAttributeValue(action, "SecurityCodeLength"), out securityCodeLength)) { securityCodeLength = 3; } using (var uow = new Rock.Data.UnitOfWorkScope()) { var attendanceCodeService = new AttendanceCodeService(); var attendanceService = new AttendanceService(); var groupMemberService = new GroupMemberService(); foreach (var family in checkInState.CheckIn.Families.Where(f => f.Selected)) { foreach (var person in family.People.Where(p => p.Selected)) { var attendanceCode = attendanceCodeService.GetNew(securityCodeLength); person.SecurityCode = attendanceCode.Code; foreach (var groupType in person.GroupTypes.Where(g => g.Selected)) { foreach (var group in groupType.Groups.Where(g => g.Selected)) { foreach (var location in group.Locations.Where(l => l.Selected)) { if (groupType.GroupType.AttendanceRule == AttendanceRule.AddOnCheckIn && groupType.GroupType.DefaultGroupRoleId.HasValue && !groupMemberService.GetByGroupIdAndPersonId(group.Group.Id, person.Person.Id, true).Any()) { var groupMember = new GroupMember(); groupMember.GroupId = group.Group.Id; groupMember.PersonId = person.Person.Id; groupMember.GroupRoleId = groupType.GroupType.DefaultGroupRoleId.Value; groupMemberService.Add(groupMember, null); groupMemberService.Save(groupMember, null); } foreach (var schedule in location.Schedules.Where(s => s.Selected)) { // Only create one attendance record per day for each person/schedule/group/location var attendance = attendanceService.Get(startDateTime, location.Location.Id, schedule.Schedule.Id, group.Group.Id, person.Person.Id); if (attendance == null) { attendance = ((Rock.Data.RockContext)uow.DbContext).Attendances.Create(); attendance.LocationId = location.Location.Id; attendance.ScheduleId = schedule.Schedule.Id; attendance.GroupId = group.Group.Id; attendance.PersonId = person.Person.Id; attendance.DeviceId = checkInState.Kiosk.Device.Id; attendance.SearchTypeValueId = checkInState.CheckIn.SearchType.Id; attendanceService.Add(attendance, null); } attendance.AttendanceCodeId = attendanceCode.Id; attendance.StartDateTime = startDateTime; attendance.EndDateTime = null; attendance.DidAttend = true; attendanceService.Save(attendance, null); KioskLocationAttendance.AddAttendance(attendance); } } } } } } } return(true); } return(false); }
/// <summary> /// Handles the Click event of the btnSave control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param> protected void btnSave_Click(object sender, EventArgs e) { ClearErrorMessage(); if (Page.IsValid) { GroupMemberService groupMemberService = new GroupMemberService(); GroupMember groupMember; int groupMemberId = int.Parse(hfGroupMemberId.Value); GroupTypeRole role = new GroupTypeRoleService().Get(ddlGroupRole.SelectedValueAsInt() ?? 0); //check to see if the user selected a role if (role == null) { nbErrorMessage.Title = "Please select a Role"; return; } // if adding a new group member if (groupMemberId.Equals(0)) { groupMember = new GroupMember { Id = 0 }; groupMember.GroupId = hfGroupId.ValueAsInt(); //check to see if the person is alread a member of the gorup/role var existingGroupMember = groupMemberService.GetByGroupIdAndPersonIdAndGroupRoleId( hfGroupId.ValueAsInt(), ppGroupMemberPerson.SelectedValue ?? 0, ddlGroupRole.SelectedValueAsId() ?? 0); if (existingGroupMember != null) { //if so, don't add and show error message var person = new PersonService().Get((int)ppGroupMemberPerson.PersonId); nbErrorMessage.Title = "Person already added"; nbErrorMessage.Text = string.Format("{0} already belongs to the {1} role for this {2}, and cannot be added again with the same role. <a href=\"/page/{3}?groupMemberId={4}\">Click here</a> to view existing membership.", person.FullName, ddlGroupRole.SelectedItem.Text, role.GroupType.GroupTerm, RockPage.PageId, existingGroupMember.Id ); return; } } else { //load existing group member groupMember = groupMemberService.Get(groupMemberId); } int memberCountInRole = new GroupMemberService().Queryable() .Where(m => m.GroupId == groupMember.GroupId && m.GroupRoleId == role.Id && m.GroupMemberStatus == GroupMemberStatus.Active) .Count(); bool roleMembershipAboveMax = false; //if adding new active group member if (groupMemberId.Equals(0) && rblStatus.SelectedValueAsEnum <GroupMemberStatus>() == GroupMemberStatus.Active) { // verify that active count has not exceeded the max if (role.MaxCount != null && (memberCountInRole + 1) > role.MaxCount) { roleMembershipAboveMax = true; } } //if existing group member changing role or status else if (groupMemberId > 0 && (groupMember.GroupRoleId != role.Id || groupMember.GroupMemberStatus != rblStatus.SelectedValueAsEnum <GroupMemberStatus>()) && rblStatus.SelectedValueAsEnum <GroupMemberStatus>() == GroupMemberStatus.Active) { // verify that active count has not exceeded the max if (role.MaxCount != null && (memberCountInRole + 1) > role.MaxCount) { roleMembershipAboveMax = true; } } //show error if above max.. do not proceed if (roleMembershipAboveMax) { var person = new PersonService().Get((int)ppGroupMemberPerson.PersonId); nbErrorMessage.Title = string.Format("Maximum {0} Exceeded", role.Name.Pluralize()); nbErrorMessage.Text = string.Format("<br />The number of {0} for this {1} is at or above its maximum allowed limit of {2:N0} active {3}.", role.Name.Pluralize(), role.GroupType.GroupTerm, role.MaxCount, role.MaxCount == 1 ? role.GroupType.GroupMemberTerm : role.GroupType.GroupMemberTerm.Pluralize()); return; } groupMember.PersonId = ppGroupMemberPerson.PersonId.Value; groupMember.GroupRoleId = role.Id; groupMember.GroupMemberStatus = rblStatus.SelectedValueAsEnum <GroupMemberStatus>(); groupMember.LoadAttributes(); Rock.Attribute.Helper.GetEditValues(phAttributes, groupMember); if (!Page.IsValid) { return; } if (!groupMember.IsValid) { return; } RockTransactionScope.WrapTransaction(() => { if (groupMember.Id.Equals(0)) { groupMemberService.Add(groupMember, CurrentPersonId); } groupMemberService.Save(groupMember, CurrentPersonId); Rock.Attribute.Helper.SaveAttributeValues(groupMember, CurrentPersonId); }); Group group = new GroupService().Get(groupMember.GroupId); if (group.IsSecurityRole || group.GroupType.Guid.Equals(Rock.SystemGuid.GroupType.GROUPTYPE_SECURITY_ROLE.AsGuid())) { Rock.Security.Role.Flush(group.Id); Rock.Security.Authorization.Flush(); } } Dictionary <string, string> qryString = new Dictionary <string, string>(); qryString["groupId"] = hfGroupId.Value; NavigateToParentPage(qryString); }
protected void btnSave_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtFirstName.Text) || string.IsNullOrWhiteSpace(txtLastName.Text) || string.IsNullOrWhiteSpace(txtEmail.Text)) { ShowError("Missing Information", "Please enter a value for First Name, Last Name, and Email"); } else { var person = GetPerson(); if (person != null) { int groupId = int.MinValue; if (int.TryParse(GetAttributeValue("Group"), out groupId)) { using (new UnitOfWorkScope()) { var groupService = new GroupService(); var groupMemberService = new GroupMemberService(); var group = groupService.Get(groupId); if (group != null && group.GroupType.DefaultGroupRoleId.HasValue) { string linkedPage = GetAttributeValue("ConfirmationPage"); if (!string.IsNullOrWhiteSpace(linkedPage)) { var member = group.Members.Where(m => m.PersonId == person.Id).FirstOrDefault(); // If person has not registered or confirmed their registration if (member == null || member.GroupMemberStatus != GroupMemberStatus.Active) { Email email = null; Guid guid = Guid.Empty; if (Guid.TryParse(GetAttributeValue("ConfirmationEmail"), out guid)) { email = new Email(guid); } if (member == null) { member = new GroupMember(); member.GroupId = group.Id; member.PersonId = person.Id; member.GroupRoleId = group.GroupType.DefaultGroupRoleId.Value; // If a confirmation email is configured, set status to Pending otherwise set it to active member.GroupMemberStatus = email != null ? GroupMemberStatus.Pending : GroupMemberStatus.Active; groupMemberService.Add(member, CurrentPersonId); groupMemberService.Save(member, CurrentPersonId); member = groupMemberService.Get(member.Id); } // Send the confirmation if (email != null) { var mergeObjects = new Dictionary <string, object>(); mergeObjects.Add("Member", member); var pageParams = new Dictionary <string, string>(); pageParams.Add("gm", member.UrlEncodedKey); var pageReference = new Rock.Web.PageReference(linkedPage, pageParams); mergeObjects.Add("ConfirmationPage", pageReference.BuildUrl()); var recipients = new Dictionary <string, Dictionary <string, object> >(); recipients.Add(person.Email, mergeObjects); email.Send(recipients); } ShowSuccess(GetAttributeValue("SuccessMessage")); } else { var pageParams = new Dictionary <string, string>(); pageParams.Add("gm", member.UrlEncodedKey); var pageReference = new Rock.Web.PageReference(linkedPage, pageParams); Response.Redirect(pageReference.BuildUrl(), false); } } else { ShowError("Configuration Error", "Invalid Confirmation Page setting"); } } else { ShowError("Configuration Error", "The configured group does not exist, or it's group type does not have a default role configured."); } } } else { ShowError("Configuration Error", "Invalid Group setting"); } } } }