public static GroupMemberDto From(GroupMemberStatus status, Account account) => new GroupMemberDto() { AccountId = account.Id, Email = account.Email, Password = account.Password, GroupMemberStatus = status.ToString() };
/// <summary> /// Adds the person to group. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="person">The person.</param> /// <param name="workflowType">Type of the workflow.</param> /// <param name="groupMembers">The group members.</param> private void AddPersonToGroup(RockContext rockContext, Person person, WorkflowTypeCache workflowType, List <GroupMember> groupMembers) { if (person != null) { GroupMember groupMember = null; if (!_group.Members .Any(m => m.PersonId == person.Id && m.GroupRoleId == _defaultGroupRole.Id)) { var groupMemberService = new GroupMemberService(rockContext); groupMember = new GroupMember(); groupMember.PersonId = person.Id; groupMember.GroupRoleId = _defaultGroupRole.Id; groupMember.GroupMemberStatus = ( GroupMemberStatus )GetAttributeValue("GroupMemberStatus").AsInteger(); groupMember.GroupId = _group.Id; groupMemberService.Add(groupMember); rockContext.SaveChanges(); } else { GroupMemberStatus status = ( GroupMemberStatus )GetAttributeValue("GroupMemberStatus").AsInteger(); groupMember = _group.Members.Where(m => m.PersonId == person.Id && m.GroupRoleId == _defaultGroupRole.Id).FirstOrDefault(); if (groupMember.GroupMemberStatus != status) { var groupMemberService = new GroupMemberService(rockContext); // reload this group member in the current context groupMember = groupMemberService.Get(groupMember.Id); groupMember.GroupMemberStatus = status; rockContext.SaveChanges(); } } if (groupMember != null) { groupMember.LoadAttributes(); groupMember.SetAttributeValue("RSVPCount", numHowMany.Value); groupMember.SaveAttributeValues(); SendGroupEmail(groupMember); } if (groupMember != null && workflowType != null && (workflowType.IsActive ?? true)) { try { List <string> workflowErrors; var workflow = Workflow.Activate(workflowType, person.FullName); new WorkflowService(rockContext).Process(workflow, groupMember, out workflowErrors); } catch (Exception ex) { ExceptionLogService.LogException(ex, this.Context); } } } }
public bool UpdateMemberGroupRequest(int groupId, int memberId, GroupMemberStatus GroupStatus) { var g = GetGroupMember(groupId, memberId); if (g != null) { g.Status = (int)GroupStatus; DataContext.SubmitChanges(); return(true); } return(false); }
public void AddMemberToGroup(int groupId, int memberId, int Level, GroupMemberStatus Status) { GroupsMember g = new GroupsMember { GroupID = groupId, MemberID = memberId, MemberLevel = Level, Status = (int)Status, DateJoined = DateTime.Now }; DataContext.GroupsMembers.InsertOnSubmit(g); DataContext.SubmitChanges(); }
/// <summary> /// Initializes a new instance of the <see cref="GroupMemberChangeTransaction"/> class. /// </summary> /// <param name="entry">The entry.</param> public GroupMemberChangeTransaction(DbEntityEntry entry) { // If entity was a group member, save the values var groupMember = entry.Entity as GroupMember; if (groupMember != null) { State = entry.State; GroupId = groupMember.GroupId; PersonId = groupMember.PersonId; GroupMemberStatus = groupMember.GroupMemberStatus; GroupMemberRoleId = groupMember.GroupRoleId; IsArchived = groupMember.IsArchived; if (groupMember.Group != null) { GroupTypeId = groupMember.Group.GroupTypeId; } // If this isn't a new group member, get the previous status and role values if (State != EntityState.Added) { var dbStatusProperty = entry.Property("GroupMemberStatus"); if (dbStatusProperty != null) { PreviousGroupMemberStatus = ( GroupMemberStatus )dbStatusProperty.OriginalValue; } var dbRoleProperty = entry.Property("GroupRoleId"); if (dbRoleProperty != null) { PreviousGroupMemberRoleId = ( int )dbRoleProperty.OriginalValue; } var dbIsArchived = entry.Property("IsArchived"); if (dbIsArchived != null) { PreviousIsArchived = ( bool )dbIsArchived.OriginalValue; } } // If this isn't a deleted group member, get the group member guid if (State != EntityState.Deleted) { GroupMemberGuid = groupMember.Guid; } } }
public DataTable GetGroupMembers(int groupId, string max, GroupMemberStatus Status) { string _max = "100 PERCENT"; if (!string.IsNullOrEmpty(max)) { _max = max.ToString(); } StringBuilder sql = new StringBuilder(string.Format("select Top {0} GroupsMembersView.* from GroupsMembersView where 1=1", _max)); sql.Append(string.Format(" and groupId={0} and memberstatus={1}", groupId, (int)Status)); sql.Append(" order by GroupsMembersView.UserName"); return(DBUtils.GetDataSet(sql.ToString(), cte.lib).Tables[0]); }
public string GetGroupMembersSelectCommand(int groupId, string max, GroupMemberStatus Status, string Cond) { string _max = "100 PERCENT"; if (!string.IsNullOrEmpty(max)) { _max = max.ToString(); } StringBuilder sql = new StringBuilder(string.Format("select Top {0} GroupsMembersView.* from GroupsMembersView where 1=1", _max)); sql.Append(string.Format(" and groupId={0} and memberstatus={1} {2}", groupId, (int)Status, Cond)); sql.Append(" order by GroupsMembersView.UserName"); return(sql.ToString()); }
protected string StyleStatusLabel(object Status) { GroupMemberStatus _status = ( GroupMemberStatus )Status; switch (_status) { case GroupMemberStatus.Inactive: return("label-danger pull-right"); case GroupMemberStatus.Active: return("label-success pull-right"); case GroupMemberStatus.Pending: return("label-info pull-right"); default: return("label-info pull-right"); } }
/// <summary> /// Initializes a new instance of the <see cref="GroupMemberChangeTransaction"/> class. /// </summary> /// <param name="entry">The entry.</param> public GroupMemberChangeTransaction( DbEntityEntry entry ) { // If entity was a group member, save the values var groupMember = entry.Entity as GroupMember; if ( groupMember != null ) { State = entry.State; GroupId = groupMember.GroupId; PersonId = groupMember.PersonId; GroupMemberStatus = groupMember.GroupMemberStatus; GroupMemberRoleId = groupMember.GroupRoleId; if ( groupMember.Group != null ) { GroupTypeId = groupMember.Group.GroupTypeId; } // If this isn't a new group member, get the previous status and role values if ( State != EntityState.Added ) { var dbStatusProperty = entry.Property( "GroupMemberStatus" ); if ( dbStatusProperty != null ) { PreviousGroupMemberStatus = (GroupMemberStatus)dbStatusProperty.OriginalValue; } var dbRoleProperty = entry.Property( "GroupRoleId" ); if ( dbRoleProperty != null ) { PreviousGroupMemberRoleId = (int)dbRoleProperty.OriginalValue; } } // If this isn't a deleted group member, get the group member guid if ( State != EntityState.Deleted ) { GroupMemberGuid = groupMember.Guid; } } }
private bool QualifiersMatch(RockContext rockContext, GroupMemberWorkflowTrigger workflowTrigger, GroupMemberStatus prevStatus, GroupMemberStatus status) { var qualifierParts = (workflowTrigger.TypeQualifier ?? "").Split(new char[] { '|' }); bool matches = true; if (matches && qualifierParts.Length > 0 && !string.IsNullOrWhiteSpace(qualifierParts[0])) { matches = qualifierParts[0].AsInteger() == status.ConvertToInt(); } if (matches && qualifierParts.Length > 2 && !string.IsNullOrWhiteSpace(qualifierParts[2])) { matches = qualifierParts[2].AsInteger() == prevStatus.ConvertToInt(); } return(matches); }
private bool QualifiersMatch(RockContext rockContext, GroupMemberWorkflowTrigger workflowTrigger, GroupMemberStatus prevStatus, GroupMemberStatus status, int prevRoleId, int roleId) { return(QualifiersMatch(rockContext, workflowTrigger, prevStatus, status) && QualifiersMatch(rockContext, workflowTrigger, prevRoleId, roleId)); }
/// <summary> /// Unigrid OnExternalDataBound event. /// </summary> protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { GroupMemberStatus status = GroupMemberStatus.Approved; DataRowView drv = null; GridViewRow gvr = null; bool current = false; switch (sourceName.ToLowerCSafe()) { case "memberapprovedwhen": case "memberrejectedwhen": if (parameter != DBNull.Value) { // Get current dateTime return(CMSContext.ConvertDateTime(Convert.ToDateTime(parameter), this)); } break; case "approve": gvr = parameter as GridViewRow; if (gvr != null) { drv = gvr.DataItem as DataRowView; if (drv != null) { // Check for current user if (IsLiveSite && (CMSContext.CurrentUser.UserID == ValidationHelper.GetInteger(drv["MemberUserID"], 0))) { current = true; } // Do not allow approve hidden or disabled users bool hiddenOrDisabled = IsUserHiddenOrDisabled(drv); status = (GroupMemberStatus)ValidationHelper.GetInteger(drv["MemberStatus"], 0); // Enable or disable Approve button if (!current && (status != GroupMemberStatus.Approved) && !hiddenOrDisabled) { ImageButton button = ((ImageButton)sender); button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Approve.png"); button.ToolTip = GetString("general.approve"); button.Enabled = true; } else { ImageButton button = ((ImageButton)sender); button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/approvedisabled.png"); button.ToolTip = GetString("general.approve"); button.Enabled = false; } } } break; case "reject": gvr = parameter as GridViewRow; if (gvr != null) { drv = gvr.DataItem as DataRowView; if (drv != null) { // Check for current user if (IsLiveSite && (CMSContext.CurrentUser.UserID == ValidationHelper.GetInteger(drv.Row["MemberUserID"], 0))) { current = true; } status = (GroupMemberStatus)ValidationHelper.GetInteger(drv["MemberStatus"], 0); // Enable or disable Reject button if (!current && (status != GroupMemberStatus.Rejected)) { ImageButton button = ((ImageButton)sender); button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Reject.png"); button.ToolTip = GetString("general.reject"); button.Enabled = true; } else { ImageButton button = ((ImageButton)sender); button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/rejectdisabled.png"); button.ToolTip = GetString("general.reject"); button.Enabled = false; } } } break; case "formattedusername": // Format username return(HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(Convert.ToString(parameter), IsLiveSite))); case "edit": gvr = parameter as GridViewRow; if (gvr != null) { drv = gvr.DataItem as DataRowView; if (drv != null) { // Do not allow approve hidden or disabled users bool hiddenOrDisabled = IsUserHiddenOrDisabled(drv); // Enable or disable Edit button if (!hiddenOrDisabled) { ImageButton button = ((ImageButton)sender); button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/Edit.png"); button.ToolTip = GetString("general.edit"); button.Enabled = true; } else { ImageButton button = ((ImageButton)sender); button.ImageUrl = GetImageUrl("Design/Controls/UniGrid/Actions/editdisabled.png"); button.ToolTip = GetString("general.edit"); button.Enabled = false; } } } break; } return(parameter); }
public string GetGroupMembersSelectCommand(int groupId, string max, GroupMemberStatus Status) { return(GetGroupMembersSelectCommand(groupId, max, Status, "")); }
/// <summary> /// Get the list of members in a group /// </summary> /// <param name="UniqueName"></param> /// <param name="max"></param> /// <returns></returns> /// public DataTable GetGroupMembers(string UniqueName, string max, GroupMemberStatus Status) { return(GetGroupMembers(GetGroup(StringUtils.SQLEncode(UniqueName)).ID, max, Status)); }
private bool QualifiersMatch( RockContext rockContext, GroupMemberWorkflowTrigger workflowTrigger, GroupMemberStatus prevStatus, GroupMemberStatus status ) { var qualifierParts = ( workflowTrigger.TypeQualifier ?? "" ).Split( new char[] { '|' } ); bool matches = true; if ( matches && qualifierParts.Length > 0 && !string.IsNullOrWhiteSpace( qualifierParts[0] ) ) { matches = qualifierParts[0].AsInteger() == status.ConvertToInt(); } if ( matches && qualifierParts.Length > 2 && !string.IsNullOrWhiteSpace( qualifierParts[2] ) ) { matches = qualifierParts[2].AsInteger() == prevStatus.ConvertToInt(); } return matches; }
private bool QualifiersMatch( RockContext rockContext, GroupMemberWorkflowTrigger workflowTrigger, GroupMemberStatus prevStatus, GroupMemberStatus status, int prevRoleId, int roleId ) { return QualifiersMatch( rockContext, workflowTrigger, prevStatus, status ) && QualifiersMatch( rockContext, workflowTrigger, prevRoleId, roleId ); }
private void BuildGroupMemberAttributes( int? groupId, int? groupMemberRoleId, GroupMemberStatus? groupMemberStatus, bool setValues ) { phGroupMemberAttributes.Controls.Clear(); phGroupMemberAttributesView.Controls.Clear(); if ( groupId.HasValue && groupMemberRoleId.HasValue && groupMemberStatus != null ) { using ( var rockContext = new RockContext() ) { var group = new GroupService( rockContext ).Get( groupId.Value ); var role = new GroupTypeRoleService( rockContext ).Get( groupMemberRoleId.Value ); if ( group != null && role != null ) { var groupMember = new GroupMember(); groupMember.Group = group; groupMember.GroupId = group.Id; groupMember.GroupRole = role; groupMember.GroupRoleId = role.Id; groupMember.GroupMemberStatus = groupMemberStatus.Value; groupMember.LoadAttributes(); if ( setValues && !string.IsNullOrWhiteSpace( hfGroupMemberAttributeValues.Value ) ) { var savedValues = JsonConvert.DeserializeObject<Dictionary<string, string>>( hfGroupMemberAttributeValues.Value ); if ( savedValues != null ) { foreach( var item in savedValues ) { groupMember.SetAttributeValue( item.Key, item.Value ); } } } Rock.Attribute.Helper.AddEditControls( groupMember, phGroupMemberAttributes, setValues, BlockValidationGroup, 2 ); Rock.Attribute.Helper.AddDisplayControls( groupMember, phGroupMemberAttributesView, null, false, false ); } } } }
public string GetGroupMembersSelectCommand(string UniqueName, string max, GroupMemberStatus Status, string Cond) { return(GetGroupMembersSelectCommand(GetGroup(StringUtils.SQLEncode(UniqueName)).ID, max, Status, Cond)); }
/// <summary> /// Unigrid OnExternalDataBound event. /// </summary> protected object gridElem_OnExternalDataBound(object sender, string sourceName, object parameter) { GroupMemberStatus status = GroupMemberStatus.Approved; DataRowView drv = null; GridViewRow gvr = null; bool current = false; switch (sourceName.ToLowerCSafe()) { case "memberapprovedwhen": case "memberrejectedwhen": if (parameter != DBNull.Value) { // Get current dateTime return(TimeZoneUIMethods.ConvertDateTime(Convert.ToDateTime(parameter), this)); } break; case "approve": gvr = parameter as GridViewRow; if (gvr != null) { drv = gvr.DataItem as DataRowView; if (drv != null) { // Check for current user if (IsLiveSite && (MembershipContext.AuthenticatedUser.UserID == ValidationHelper.GetInteger(drv["MemberUserID"], 0))) { current = true; } // Do not allow approve hidden or disabled users bool hiddenOrDisabled = IsUserHiddenOrDisabled(drv); status = (GroupMemberStatus)ValidationHelper.GetInteger(drv["MemberStatus"], 0); // Enable or disable Approve button if (!current && (status != GroupMemberStatus.Approved) && !hiddenOrDisabled) { CMSGridActionButton button = ((CMSGridActionButton)sender); button.IconCssClass = "icon-check-circle"; button.IconStyle = GridIconStyle.Allow; button.ToolTip = GetString("general.approve"); button.Enabled = true; } else { CMSGridActionButton button = ((CMSGridActionButton)sender); button.IconCssClass = "icon-check-circle"; button.IconStyle = GridIconStyle.Allow; button.ToolTip = GetString("general.approve"); button.Enabled = false; } } } break; case "reject": gvr = parameter as GridViewRow; if (gvr != null) { drv = gvr.DataItem as DataRowView; if (drv != null) { // Check for current user if (IsLiveSite && (MembershipContext.AuthenticatedUser.UserID == ValidationHelper.GetInteger(drv.Row["MemberUserID"], 0))) { current = true; } status = (GroupMemberStatus)ValidationHelper.GetInteger(drv["MemberStatus"], 0); // Enable or disable Reject button if (!current && (status != GroupMemberStatus.Rejected)) { CMSGridActionButton button = ((CMSGridActionButton)sender); button.IconCssClass = "icon-times-circle"; button.IconStyle = GridIconStyle.Critical; button.ToolTip = GetString("general.reject"); button.Enabled = true; } else { CMSGridActionButton button = ((CMSGridActionButton)sender); button.IconCssClass = "icon-times-circle"; button.IconStyle = GridIconStyle.Critical; button.ToolTip = GetString("general.reject"); button.Enabled = false; } } } break; case "formattedusername": // Format username return(HTMLHelper.HTMLEncode(Functions.GetFormattedUserName(Convert.ToString(parameter), IsLiveSite))); case "edit": gvr = parameter as GridViewRow; if (gvr != null) { drv = gvr.DataItem as DataRowView; if (drv != null) { // Do not allow approve hidden or disabled users bool hiddenOrDisabled = IsUserHiddenOrDisabled(drv); // Enable or disable Edit button if (!hiddenOrDisabled) { CMSGridActionButton button = ((CMSGridActionButton)sender); button.IconCssClass = "icon-edit"; button.IconStyle = GridIconStyle.Allow; button.ToolTip = GetString("general.edit"); button.Enabled = true; } else { CMSGridActionButton button = ((CMSGridActionButton)sender); button.IconCssClass = "icon-edit"; button.IconStyle = GridIconStyle.Allow; button.ToolTip = GetString("general.edit"); button.Enabled = false; } } } break; } return(parameter); }
/// <summary> /// Get a list of GroupMember records for the user's selection. This includes all new /// GroupMember records that would need to be saved into the database as well as any /// existing membership records. /// </summary> /// <returns>List of GroupMember objects for the current person.</returns> List <GroupMember> GetMembershipRecords(RockContext rockContext = null) { if (rockContext == null) { rockContext = new RockContext(); } List <GroupMember> groupsMembership = new List <GroupMember>(); List <GroupMember> attributeMembers = new List <GroupMember>(); GroupMemberService memberService = new GroupMemberService(rockContext); GroupService groupService = new GroupService(rockContext); Person person = new PersonService(rockContext).Get(_person.Id); GroupMemberStatus status = ( GroupMemberStatus )Enum.Parse(typeof(GroupMemberStatus), (GetAttributeValue("AddAsStatus") ?? string.Empty)); foreach (string g in hfSelection.Value.Split(',')) { GroupMember member = null; Group group = null; Guid groupGuid = g.AsGuid(); // // Could not parse the GUID or find the Group, skip it. // if (groupGuid == Guid.Empty || (group = groupService.Get(groupGuid)).Id == 0) { continue; } // // Do not allow people to add to security groups. // if (group.IsSecurityRole && !string.IsNullOrWhiteSpace(PageParameter("Group"))) { continue; } // // Find the existing record, otherwise create a new one. // member = group.Members.Where(gm => gm.PersonId == _person.Id).FirstOrDefault(); if (member == null) { member = new GroupMember { Id = 0 }; rockContext.GroupMembers.Add(member); member.Group = group; member.GroupId = member.Group.Id; member.Person = person; member.PersonId = member.Person.Id; member.DateTimeAdded = RockDateTime.Now; member.GroupRoleId = member.Group.GroupType.DefaultGroupRoleId ?? 0; member.GroupMemberStatus = status; } else if (member.GroupMemberStatus == GroupMemberStatus.Inactive) { // // We only update the status if it is Inactive. // member.GroupMemberStatus = status; } member.LoadAttributes(rockContext); groupsMembership.Add(member); } return(groupsMembership); }