Ejemplo n.º 1
0
        private async Task DeleteGroupAsync(Data.Group group, bool withChildren = true)
        {
            if (group != null)
            {
                var memberShips = await this.context.Set <Data.Membership>().Where(m => m.GroupId == group.Id).ToListAsync();

                foreach (var memberShip in memberShips)
                {
                    if (withChildren)
                    {
                        var childGroup = await this.GetEntityAsync <Data.Group>(g => g.Id == memberShip.PrincipalId);

                        if (childGroup != null)
                        {
                            await this.DeleteGroupAsync(childGroup);
                        }
                    }

                    this.context.Set <Data.Membership>().Remove(memberShip);
                }

                await this.UnaffectRolesFromGroupAsync(group);

                this.context.Set <Data.Group>().Remove(group);

                var principal = group.Principal;
                if (principal == null)
                {
                    principal = await this.GetEntityAsync <Data.Principal>(x => x.Id == group.Id);
                }

                this.context.Set <Data.Principal>().Remove(principal);
            }
        }
Ejemplo n.º 2
0
 private async Task UnaffectRolesFromGroupAsync(Data.Group group)
 {
     if (group != null)
     {
         await this.UnaffectFromPrincipalAsync(group.Id);
     }
 }
Ejemplo n.º 3
0
        public async Task UnaffectRoleFromGroupOnScopeAsync(string roleName, string groupName, string scopeName)
        {
            Data.Group group = await this.GetEntityAsync <Data.Group>(r => r.Name == groupName);

            if (group != null)
            {
                await this.UnaffectRoleFromPrincipalOnScopeAsync(roleName, group.Id, scopeName);
            }
        }
Ejemplo n.º 4
0
        public async Task <IGroup> CreateGroupAsync(string groupName, string parentGroupName = null)
        {
            var group = await this.GetEntityAsync <Data.Group>(r => r.Name == groupName);

            if (group == null)
            {
                var principal = new Data.Principal
                {
                    Id             = Guid.NewGuid(),
                    CreationBy     = this.principalIdProvider.PrincipalId,
                    ModificationBy = this.principalIdProvider.PrincipalId
                };
                group = new Data.Group(principal)
                {
                    Name = groupName
                };

                this.context.Set <Data.Group>().Add(group);

                if (parentGroupName != null)
                {
                    await this.CreateGroupAsync(parentGroupName);

                    var parentGoup = await this.GetEntityAsync <Data.Group>(r => r.Name == parentGroupName);

                    this.context.Set <Data.Membership>().Add(new Data.Membership
                    {
                        CreationBy     = principal.CreationBy,
                        ModificationBy = principal.ModificationBy,
                        PrincipalId    = group.Id,
                        Group          = parentGoup
                    });
                }
            }
            return(group);
        }
Ejemplo n.º 5
0
        public async Task UnaffectRolesFromGroupAsync(string groupName)
        {
            Data.Group group = await this.GetEntityAsync <Data.Group>(r => r.Name == groupName);

            await this.UnaffectRolesFromGroupAsync(group);
        }