public static DataView GetGroups(bool includeOrganizationAdministratorGroup) { ClientDataSet.GroupDataTable table = GetGroups() as ClientDataSet.GroupDataTable; if (!table.Columns.Contains("SortNumber")) { table.Columns.Add("SortNumber", typeof(int), "IIF((GroupId = '00000000-0000-0000-0000-000000000000'), 0, IIF((BuiltIn = 'True'), 1, 2))"); } if (includeOrganizationAdministratorGroup) { if (table.Columns.Contains("SortNumber")) { if (table.FindByGroupId(Guid.Empty) == null) { ClientDataSet.GroupRow row = table.NewGroupRow(); row.GroupId = Guid.Empty; row.OrganizationId = UserContext.Current.OrganizationId; row.Name = Resources.GroupProvider_OrganizationAdministratorGroupName; row.Description = Resources.GroupProvider_OrganizationAdministratorGroupDescription; row.BuiltIn = true; table.AddGroupRow(row); table.AcceptChanges(); } } } table.DefaultView.Sort = string.Format(CultureInfo.InvariantCulture, "SortNumber, {0}", table.NameColumn.ColumnName); return(table.DefaultView); }
/// <summary> /// Creates new group with specified details in specified organization. /// </summary> /// <param name="name">The name of the group.</param> /// <param name="description">The group description.</param> /// <param name="organizationId">The identifier of the organization.</param> /// <param name="builtIn">Whether the group is built-in.</param> /// <returns>The System.Guid that represents the identifier of the newly created group.</returns> internal static Guid InsertGroup(string name, string description, Guid organizationId, bool builtIn) { ClientDataSet.GroupDataTable table = new ClientDataSet.GroupDataTable(); ClientDataSet.GroupRow row = table.NewGroupRow(); row.GroupId = Guid.NewGuid(); row.Name = name; row.Description = description; row.OrganizationId = organizationId; row.BuiltIn = builtIn; try { table.AddGroupRow(row); } catch (ConstraintException ex) { throw new ConstraintException(string.Format(CultureInfo.CurrentCulture, Resources.GroupProvider_ErrorMessage_GroupAlreadyExists, name), ex); } using (GroupTableAdapter adapter = new GroupTableAdapter(OrganizationProvider.GetConnectionString(organizationId))) { adapter.Update(row); } Guid groupId = row.GroupId; return(groupId); }
public static DataTable GetGroups() { Guid organizationId = UserContext.Current.OrganizationId; if (FrameworkConfiguration.Current.WebApplication.EnableMultipleInstances) { return(GetGroups(organizationId)); } else { ClientDataSet.GroupDataTable table = GetGroups(organizationId); Instance firstInstance = InstanceProvider.GetFirstInstance(organizationId); if (firstInstance != null) { ArrayList list = new ArrayList(); ClientDataSet.GroupsInstancesRolesDataTable girTable = null; using (GroupsInstancesRolesTableAdapter adapter = new GroupsInstancesRolesTableAdapter(OrganizationProvider.GetConnectionString(organizationId))) { girTable = adapter.GetGroupsInstancesRolesByInstanceId(organizationId, firstInstance.InstanceId); } foreach (ClientDataSet.GroupsInstancesRolesRow girRow in girTable) { if (girRow.RoleId == RoleProvider.InstanceAdministratorRoleId) { if (!list.Contains(girRow.GroupId)) { list.Add(girRow.GroupId); } } } foreach (Guid groupId in list) { ClientDataSet.GroupRow row = table.FindByGroupId(groupId); if (row != null) { table.RemoveGroupRow(row); } } table.AcceptChanges(); } return(table); } }
/// <summary> /// Updates the name of the built-in group that is associated to the specified instance. /// </summary> /// <param name="ds">The data sourceRow.</param> /// <param name="instanceId">The unique identifier of the instance.</param> /// <param name="name">The name of the instance.</param> internal static void UpdateInstanceAdministratorGroup(Guid organizationId, Guid instanceId, string name) { using (GroupTableAdapter adapter = new GroupTableAdapter(OrganizationProvider.GetConnectionString(organizationId))) { ClientDataSet.GroupDataTable table = adapter.GetGroupsByRoles(organizationId, ((instanceId == Guid.Empty) ? null : new Guid?(instanceId)), RoleProvider.InstanceAdministratorRoleId.ToString().ToUpperInvariant()); if (table.Count > 0) { ClientDataSet.GroupRow row = table[0]; try { row.Name = string.Format(CultureInfo.InvariantCulture, Resources.GroupProvider_InstanceAdministratorGroup_Name, name); } catch (ConstraintException ex) { throw new ConstraintException(string.Format(CultureInfo.CurrentCulture, Resources.GroupProvider_ErrorMessage_GroupAlreadyExists, name), ex); } row.Description = Resources.GroupProvider_InstanceAdministratorGroup_Description; adapter.Update(row); } } }