Example #1
0
        public async Task <Group> AddUserToGroup(Group group, User user)
        {
            var groupUser = new GroupUser
            {
                GroupId          = Guid.Parse(group.Id),
                SubjectId        = user.SubjectId,
                IdentityProvider = user.IdentityProvider
            };

            _authorizationDbContext.GroupUsers.Add(groupUser);
            await _authorizationDbContext.SaveChangesAsync();

            return(group);
        }
        public async Task <Group> AddUserToGroup(Group group, User user)
        {
            var groupUser = new GroupUser
            {
                GroupId          = Guid.Parse(group.Id),
                SubjectId        = user.SubjectId,
                IdentityProvider = user.IdentityProvider
            };

            AuthorizationDbContext.GroupUsers.Add(groupUser);
            await AuthorizationDbContext.SaveChangesAsync();

            await EventService.RaiseEventAsync(new EntityAuditEvent <Group>(EventTypes.ChildEntityCreatedEvent, group.Id, group));

            return(group);
        }
Example #3
0
        public async Task <Group> DeleteUserFromGroup(Group group, User user)
        {
            var userInGroup = await _authorizationDbContext.GroupUsers
                              .SingleOrDefaultAsync(gu =>
                                                    gu.SubjectId.Equals(user.SubjectId, StringComparison.OrdinalIgnoreCase) &&
                                                    gu.IdentityProvider.Equals(user.IdentityProvider, StringComparison.OrdinalIgnoreCase) &&
                                                    gu.GroupId == Guid.Parse(group.Id));

            if (userInGroup != null)
            {
                userInGroup.IsDeleted = true;
                _authorizationDbContext.GroupUsers.Update(userInGroup);
                await _authorizationDbContext.SaveChangesAsync();
            }

            return(group);
        }
        public async Task <Group> DeleteUserFromGroup(Group group, User user)
        {
            var groupUser = await AuthorizationDbContext.GroupUsers
                            .SingleOrDefaultAsync(gu =>
                                                  gu.SubjectId == user.SubjectId &&
                                                  gu.IdentityProvider == user.IdentityProvider &&
                                                  gu.GroupId == group.Id && !gu.IsDeleted);

            if (groupUser == null)
            {
                return(group);
            }

            groupUser.IsDeleted = true;
            AuthorizationDbContext.GroupUsers.Update(groupUser);
            await AuthorizationDbContext.SaveChangesAsync();

            await EventService.RaiseEventAsync(new EntityAuditEvent <Group>(EventTypes.ChildEntityDeletedEvent,
                                                                            groupUser.Id.ToString(), group));

            return(group);
        }