/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns(int?groupTypeId) { GroupRoleService groupRoleService = new GroupRoleService(); List <GroupRole> groupRoles = groupRoleService.Queryable().Where(a => a.GroupTypeId == groupTypeId).OrderBy(a => a.Name).ToList(); groupRoles.Insert(0, new GroupRole { Id = None.Id, Name = None.Text }); ddlDefaultGroupRole.DataSource = groupRoles; ddlDefaultGroupRole.DataBind(); ddlAttendanceRule.BindToEnum(typeof(Rock.Model.AttendanceRule)); ddlAttendancePrintTo.BindToEnum(typeof(Rock.Model.PrintTo)); ddlLocationSelectionMode.BindToEnum(typeof(Rock.Model.LocationPickerMode)); gtpInheritedGroupType.GroupTypes = new GroupTypeService().Queryable() .Where(g => g.Id != groupTypeId) .ToList(); var groupTypePurposeList = new DefinedValueService().GetByDefinedTypeGuid(new Guid(Rock.SystemGuid.DefinedType.GROUPTYPE_PURPOSE)).OrderBy(a => a.Name).ToList(); ddlGroupTypePurpose.Items.Clear(); ddlGroupTypePurpose.Items.Add(Rock.Constants.None.ListItem); foreach (var item in groupTypePurposeList) { ddlGroupTypePurpose.Items.Add(new ListItem(item.Name, item.Id.ToString())); } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { GroupRoleService groupRoleService = new GroupRoleService(); SortProperty sortProperty = gGroupRoles.SortProperty; var qry = groupRoleService.Queryable().Select(a => new { a.Id, a.Name, a.Description, GroupTypeName = a.GroupType.Name, a.IsSystem }); if (sortProperty != null) { gGroupRoles.DataSource = qry.Sort(sortProperty).ToList(); } else { gGroupRoles.DataSource = qry.OrderBy(p => p.Name).ToList(); } gGroupRoles.DataBind(); }
/// <summary> /// Shows the edit. /// </summary> /// <param name="groupRoleId">The group role id.</param> protected void ShowEdit(int groupRoleId) { pnlList.Visible = false; pnlDetails.Visible = true; GroupRoleService groupRoleService = new GroupRoleService(); GroupRole groupRole = groupRoleService.Get(groupRoleId); bool readOnly = false; hfGroupRoleId.Value = groupRoleId.ToString(); LoadDropDowns(); if (groupRole != null) { iconIsSystem.Visible = groupRole.IsSystem; hfGroupRoleId.Value = groupRole.Id.ToString(); tbName.Text = groupRole.Name; tbDescription.Text = groupRole.Description; ddlGroupType.SelectedValue = groupRole.GroupTypeId.ToString(); tbSortOrder.Text = groupRole.SortOrder != null?groupRole.SortOrder.ToString() : string.Empty; tbMaxCount.Text = groupRole.MaxCount != null?groupRole.MaxCount.ToString() : string.Empty; tbMinCount.Text = groupRole.MinCount != null?groupRole.MinCount.ToString() : string.Empty; readOnly = groupRole.IsSystem; if (groupRole.IsSystem) { lActionTitle.Text = ActionTitle.View(GroupRole.FriendlyTypeName); btnCancel.Text = "Close"; } else { lActionTitle.Text = ActionTitle.Edit(GroupRole.FriendlyTypeName); btnCancel.Text = "Cancel"; } } else { lActionTitle.Text = ActionTitle.Add(GroupRole.FriendlyTypeName); iconIsSystem.Visible = false; hfGroupRoleId.Value = 0.ToString(); tbName.Text = string.Empty; tbDescription.Text = string.Empty; ddlGroupType.SelectedValue = null; tbSortOrder.Text = string.Empty; tbMinCount.Text = string.Empty; tbMaxCount.Text = string.Empty; } tbName.ReadOnly = readOnly; tbDescription.ReadOnly = readOnly; ddlGroupType.Enabled = !readOnly; tbSortOrder.ReadOnly = readOnly; tbMaxCount.ReadOnly = readOnly; tbMinCount.ReadOnly = readOnly; btnSave.Visible = !readOnly; }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns() { GroupRoleService groupRoleService = new GroupRoleService(); List <GroupRole> groupRoles = groupRoleService.Queryable().OrderBy(a => a.Name).ToList(); groupRoles.Insert(0, new GroupRole { Id = None.Id, Name = None.Text }); ddlDefaultGroupRole.DataSource = groupRoles; ddlDefaultGroupRole.DataBind(); }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { GroupRoleService groupRoleService = new GroupRoleService(); SortProperty sortProperty = gGroupRoles.SortProperty; if (sortProperty != null) { gGroupRoles.DataSource = groupRoleService.Queryable().Sort(sortProperty).ToList(); } else { gGroupRoles.DataSource = groupRoleService.Queryable().OrderBy(p => p.Name).ToList(); } gGroupRoles.DataBind(); }
/// <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 ); var campusi = new CampusService().Queryable().OrderBy( a => a.Name ).ToList(); cpCampus.Campuses = campusi; cpCampus.Visible = campusi.Any(); var childRole = new GroupRoleService().Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_CHILD)); if ( childRole != null ) { _childRoleId = childRole.Id; } bool.TryParse( GetAttributeValue( "RequireGender" ), out _requireGender ); bool.TryParse( GetAttributeValue( "RequireGrade" ), out _requireGrade ); }
/// <summary> /// Loads the drop downs. /// </summary> private void LoadDropDowns(int?groupTypeId) { GroupRoleService groupRoleService = new GroupRoleService(); List <GroupRole> groupRoles = groupRoleService.Queryable().Where(a => a.GroupTypeId == groupTypeId).OrderBy(a => a.Name).ToList(); groupRoles.Insert(0, new GroupRole { Id = None.Id, Name = None.Text }); ddlDefaultGroupRole.DataSource = groupRoles; ddlDefaultGroupRole.DataBind(); ddlAttendanceRule.BindToEnum(typeof(Rock.Model.AttendanceRule)); ddlAttendancePrintTo.BindToEnum(typeof(Rock.Model.PrintTo)); ddlLocationSelectionMode.BindToEnum(typeof(Rock.Model.LocationPickerMode)); gtpInheritedGroupType.GroupTypes = new GroupTypeService().Queryable() .Where(g => g.Id != groupTypeId) .ToList(); }
/// <summary> /// Handles the Delete event of the gGroupRoles 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 gGroupRoles_Delete(object sender, RowEventArgs e) { GroupRoleService groupRoleService = new GroupRoleService(); GroupRole groupRole = groupRoleService.Get((int)e.RowKeyValue); string errorMessage; if (!groupRoleService.CanDelete(groupRole, out errorMessage)) { nbGridWarning.Text = errorMessage; nbGridWarning.Visible = true; return; } if (CurrentBlock != null) { groupRoleService.Delete(groupRole, CurrentPersonId); groupRoleService.Save(groupRole, CurrentPersonId); } BindGrid(); }
private void BindFamilies() { Guid familyGroupGuid = new Guid(Rock.SystemGuid.GroupType.GROUPTYPE_FAMILY); var memberService = new GroupMemberService(); var families = memberService.Queryable() .Where(m => m.PersonId == Person.Id && m.Group.GroupType.Guid == familyGroupGuid ) .Select(m => m.Group) .ToList(); if (!families.Any()) { var role = new GroupRoleService().Get(new Guid(Rock.SystemGuid.GroupRole.GROUPROLE_FAMILY_MEMBER_ADULT)); if (role != null && role.GroupTypeId.HasValue) { var groupMember = new GroupMember(); groupMember.PersonId = Person.Id; groupMember.GroupRoleId = role.Id; var family = new Group(); family.Name = Person.LastName; family.GroupTypeId = role.GroupTypeId.Value; family.Members.Add(groupMember); var groupService = new GroupService(); groupService.Add(family, CurrentPersonId); groupService.Save(family, CurrentPersonId); families.Add(groupService.Get(family.Id)); } } rptrFamilies.DataSource = families; rptrFamilies.DataBind(); }
/// <summary> /// Handles the Delete event of the gGroupRoles 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 gGroupRoles_Delete(object sender, RowEventArgs e) { RockTransactionScope.WrapTransaction(() => { GroupRoleService groupRoleService = new GroupRoleService(); GroupRole groupRole = groupRoleService.Get((int)e.RowKeyValue); if (groupRole != null) { string errorMessage; if (!groupRoleService.CanDelete(groupRole, out errorMessage)) { mdGridWarning.Show(errorMessage, ModalAlertType.Information); return; } groupRoleService.Delete(groupRole, CurrentPersonId); groupRoleService.Save(groupRole, CurrentPersonId); } }); BindGrid(); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The item key value.</param> public void ShowDetail(string itemKey, int itemKeyValue) { if (!itemKey.Equals("groupRoleId")) { return; } pnlDetails.Visible = true; GroupRole groupRole = null; if (!itemKeyValue.Equals(0)) { groupRole = new GroupRoleService().Get(itemKeyValue); } else { groupRole = new GroupRole { Id = 0 }; } ShowDetail(groupRole); }
/// <summary> /// Shows the detail. /// </summary> /// <param name="itemKey">The item key.</param> /// <param name="itemKeyValue">The group id.</param> public void ShowDetail(string itemKey, int itemKeyValue, int?parentGroupId) { pnlDetails.Visible = false; if (!itemKey.Equals("groupId")) { return; } Group group = null; if (!itemKeyValue.Equals(0)) { group = new GroupService().Get(itemKeyValue); } else { group = new Group { Id = 0, IsActive = true, ParentGroupId = parentGroupId }; } if (group == null) { return; } pnlDetails.Visible = true; hfGroupId.Value = group.Id.ToString(); // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!IsUserAuthorized("Edit")) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(Group.FriendlyTypeName); } if (group.IsSystem) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlySystem(Group.FriendlyTypeName); } bool roleBelowMimumumMembership = false; if (bool.TryParse(PageParameter("roleBelowMin"), out roleBelowMimumumMembership)) { int roleId = 0; int.TryParse(PageParameter("roleId"), out roleId); if (roleBelowMimumumMembership && roleId > 0) { GroupRole role = new GroupRoleService().Get(roleId); if (role.MinCount != null) { int groupRoleMemberCount = GetGroupRoleMemberCount(itemKeyValue, roleId); string minumumMemberText = string.Format("The {0} role is currently below it's minimum active membership requirement of {1} {2}.", role.Name, role.MinCount, role.MinCount == 1 ? "member" : "members" ); if (nbEditModeMessage.Text.Length > 0) { nbEditModeMessage.Text = nbEditModeMessage.Text + " <br> " + minumumMemberText; } else { nbEditModeMessage.Text = "INFO: " + minumumMemberText; } } } } if (readOnly) { btnEdit.Visible = false; btnDelete.Visible = false; ShowReadonlyDetails(group); } else { btnEdit.Visible = true; btnDelete.Visible = true; if (group.Id > 0) { ShowReadonlyDetails(group); } else { ShowEditDetails(group); } } }
/// <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> /// 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) { GroupRole groupRole; GroupRoleService groupRoleService = new GroupRoleService(); int groupRoleId = int.Parse(hfGroupRoleId.Value); if (groupRoleId == 0) { groupRole = new GroupRole(); groupRole.IsSystem = false; groupRoleService.Add(groupRole, CurrentPersonId); } else { groupRole = groupRoleService.Get(groupRoleId); } groupRole.LoadAttributes(); groupRole.Name = tbName.Text; groupRole.Description = tbDescription.Text; groupRole.GroupTypeId = int.Parse(ddlGroupType.SelectedValue); groupRole.SortOrder = tbSortOrder.Text.AsInteger(); groupRole.MinCount = tbMinCount.Text.AsInteger(); groupRole.MaxCount = tbMaxCount.Text.AsInteger(); // validate Control values if (!tbSortOrder.IsValid) { return; } if (!tbMaxCount.IsValid) { return; } if (!tbMinCount.IsValid) { return; } // validate Min/Max count comparison if (groupRole.MinCount != null && groupRole.MaxCount != null) { if (groupRole.MinCount > groupRole.MaxCount) { tbMinCount.ShowErrorMessage("Min Count cannot be larger than Max Count"); return; } } if (!groupRole.IsValid) { // Controls will render the error messages return; } RockTransactionScope.WrapTransaction(() => { groupRoleService.Save(groupRole, CurrentPersonId); Rock.Attribute.Helper.GetEditValues(phAttributes, groupRole); Rock.Attribute.Helper.SaveAttributeValues(groupRole, CurrentPersonId); }); NavigateToParentPage(); }
/// <summary> /// Binds the data. /// </summary> private void BindData() { if (Person != null && Person.Id > 0) { if (ownerRoleGuid != Guid.Empty) { 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 && bool.Parse(GetAttributeValue("CreateGroup"))) { var role = new GroupRoleService().Get(ownerRoleGuid); if (role != null && role.GroupTypeId.HasValue) { var groupMember = new GroupMember(); groupMember.PersonId = Person.Id; groupMember.GroupRoleId = role.Id; group = new Group(); group.Name = role.GroupType.Name; group.GroupTypeId = role.GroupTypeId.Value; group.Members.Add(groupMember); var groupService = new GroupService(); groupService.Add(group, CurrentPersonId); groupService.Save(group, CurrentPersonId); group = groupService.Get(group.Id); } } if (group != null) { if (group.IsAuthorized("View", CurrentPerson)) { if (!string.IsNullOrWhiteSpace(group.GroupType.IconCssClass)) { phGroupTypeIcon.Controls.Add( new LiteralControl( string.Format("<i class='{0}'></i>", group.GroupType.IconCssClass))); } lGroupName.Text = group.Name; phEditActions.Visible = group.IsAuthorized("Edit", CurrentPerson); // TODO: How many implied relationships should be displayed rGroupMembers.DataSource = new GroupMemberService().GetByGroupId(group.Id) .Where(m => m.PersonId != Person.Id) .OrderBy(m => m.Person.LastName) .ThenBy(m => m.Person.FirstName) .Take(50) .ToList(); rGroupMembers.DataBind(); } } } } } }
/// <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) { GroupRole groupRole; GroupRoleService groupRoleService = new GroupRoleService(); int groupRoleId = int.Parse(hfGroupRoleId.Value); if (groupRoleId == 0) { groupRole = new GroupRole(); groupRole.IsSystem = false; groupRoleService.Add(groupRole, CurrentPersonId); } else { groupRole = groupRoleService.Get(groupRoleId); } groupRole.Name = tbName.Text; groupRole.Description = tbDescription.Text; groupRole.GroupTypeId = int.Parse(ddlGroupType.SelectedValue); groupRole.SortOrder = tbSortOrder.TextAsInteger(); groupRole.MinCount = tbMinCount.TextAsInteger(); groupRole.MaxCount = tbMaxCount.TextAsInteger(); // validate Control values if (!tbSortOrder.IsValid) { return; } if (!tbMaxCount.IsValid) { return; } if (!tbMinCount.IsValid) { return; } // validate Min/Max count comparison if (groupRole.MinCount != null && groupRole.MaxCount != null) { if (groupRole.MinCount > groupRole.MaxCount) { tbMinCount.ShowErrorMessage("Min Count cannot be larger than Max Count"); return; } } // check for duplicates within GroupType if (groupRoleService.Queryable().Where(g => (g.GroupTypeId ?? 0).Equals((groupRole.GroupTypeId ?? 0))).Count(a => a.Name.Equals(groupRole.Name, StringComparison.OrdinalIgnoreCase) && !a.Id.Equals(groupRole.Id)) > 0) { tbName.ShowErrorMessage(WarningMessage.DuplicateFoundMessage("name", Group.FriendlyTypeName)); return; } if (!groupRole.IsValid) { // Controls will render the error messages return; } groupRoleService.Save(groupRole, CurrentPersonId); BindGrid(); pnlDetails.Visible = false; pnlList.Visible = true; }