Beispiel #1
0
        public async Task DeleteAsync(DeletePermissionSet command)
        {
            var permissionSet = await _dbContext.PermissionSets
                                .Include(x => x.Categories)
                                .Include(x => x.Forums)
                                .FirstOrDefaultAsync(x =>
                                                     x.SiteId == command.SiteId &&
                                                     x.Id == command.Id &&
                                                     x.Status != StatusType.Deleted);

            if (permissionSet == null)
            {
                throw new DataException($"Permission set with Id {command.Id} not found.");
            }

            if (permissionSet.Categories.Any() || permissionSet.Forums.Any())
            {
                throw new DataException($"Permission set with Id {command.Id} is in use and cannot be deleted.");
            }

            permissionSet.Delete();

            _dbContext.Events.Add(new Event(command.SiteId,
                                            command.UserId,
                                            EventType.Deleted,
                                            typeof(PermissionSet),
                                            command.Id));

            await _dbContext.SaveChangesAsync();

            _cacheManager.Remove(CacheKeys.PermissionSet(command.Id));
        }
        public async Task <ActionResult> Delete(Guid id)
        {
            var site = await _contextService.CurrentSiteAsync();

            var user = await _contextService.CurrentUserAsync();

            var command = new DeletePermissionSet
            {
                Id     = id,
                SiteId = site.Id,
                UserId = user.Id
            };

            await _permissionSetService.DeleteAsync(command);

            return(Ok());
        }