Пример #1
0
        /// <inheritdoc />
        public async Task <BooleanObject> ConditionalDelete <T>(IQueryable <T> models, CancellationToken cancellation = default)
            where T : class, IOwnerAbstractModel, new()
        {
            try
            {
                await models.AddDeleteSecurityFiltering(_identityService, _userManager, _dbContext, _serviceProvider).DeleteAsync(cancellation);
            }
            catch (Exception e) {
                var exceptionData = e.Data;
                if (exceptionData.Contains("Detail"))
                {
                    string errorMessage = exceptionData["Detail"].ToString();
                    throw new AggregateException(new InvalidOperationException(errorMessage));
                }
                throw new AggregateException(new InvalidOperationException(e.Message));
            }


            var errors = await _securityService.CheckDbSecurityChanges(_identityService, _dbContext);

            if (errors.Any())
            {
                throw new AggregateException(errors.Select(error => new InvalidOperationException(error)));
            }
            await _dbContext.SaveChangesAsync(cancellation);

            return(new BooleanObject {
                Value = true
            });
        }