Ejemplo n.º 1
0
        /// <summary>
        ///  Delete permission and associated Group permission for roles
        /// </summary>
        /// <param name="permission"></param>
        public void Delete(Permission permission)
        {
            var catPermForRoles = _groupPermissionForRoleService.GetByPermission(permission.Id);

            foreach (var GroupPermissionForRole in catPermForRoles)
            {
                _groupPermissionForRoleService.Delete(GroupPermissionForRole);
            }

            _context.Permission.Remove(permission);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public async Task <IPipelineProcess <Group> > Process(IPipelineProcess <Group> input,
                                                              IMvcForumContext context)
        {
            _groupPermissionForRoleService.RefreshContext(context);
            _notificationService.RefreshContext(context);

            try
            {
                // Check if anyone else if using this role
                var okToDelete = !input.EntityToProcess.Topics.Any();

                if (okToDelete)
                {
                    // Get any Grouppermissionforoles and delete these first
                    var rolesToDelete = _groupPermissionForRoleService.GetByGroup(input.EntityToProcess.Id);

                    foreach (var GroupPermissionForRole in rolesToDelete)
                    {
                        _groupPermissionForRoleService.Delete(GroupPermissionForRole);
                    }

                    var GroupNotificationsToDelete = new List <GroupNotification>();
                    GroupNotificationsToDelete.AddRange(input.EntityToProcess.GroupNotifications);
                    foreach (var GroupNotification in GroupNotificationsToDelete)
                    {
                        _notificationService.Delete(GroupNotification);
                    }

                    context.Group.Remove(input.EntityToProcess);

                    await context.SaveChangesAsync();

                    _cacheService.ClearStartsWith("GroupList");
                }
                else
                {
                    input.AddError($"In use by {input.EntityToProcess.Topics} entities");
                    return(input);
                }
            }
            catch (Exception ex)
            {
                input.AddError(ex.Message);
                _loggingService.Error(ex);
            }

            return(input);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Delete a role
        /// </summary>
        /// <param name="role"></param>
        public void Delete(MembershipRole role)
        {
            // Check if anyone else if using this role
            var okToDelete = role.Users.Count == 0;

            if (okToDelete)
            {
                // Get any Grouppermissionforoles and delete these first
                var rolesToDelete = _groupPermissionForRoleService.GetByRole(role.Id);

                foreach (var GroupPermissionForRole in rolesToDelete)
                {
                    _groupPermissionForRoleService.Delete(GroupPermissionForRole);
                }

                _context.MembershipRole.Remove(role);
            }
            else
            {
                var inUseBy = new List <IBaseEntity>();
                inUseBy.AddRange(role.Users);
                throw new Exception($"In use by {inUseBy.Count} entities");
            }
        }