public virtual async Task DeleteAsync(TId id)
        {
            _logger.LogTrace($"Entering {nameof(DeleteAsync)}('{id}').");

            if (!IsNull(_hookExecutor))
            {
                var entity = _resourceFactory.CreateInstance <TResource>();
                entity.Id = id;

                _hookExecutor.BeforeDelete(AsList(entity), ResourcePipeline.Delete);
            }

            var succeeded = await _repository.DeleteAsync(id);

            if (!succeeded)
            {
                string resourceId = TypeHelper.GetResourceStringId <TResource, TId>(id, _resourceFactory);
                throw new ResourceNotFoundException(resourceId, _currentRequestResource.ResourceName);
            }

            if (!IsNull(_hookExecutor))
            {
                var entity = _resourceFactory.CreateInstance <TResource>();
                entity.Id = id;

                _hookExecutor.AfterDelete(AsList(entity), ResourcePipeline.Delete, succeeded);
            }
        }
        /// <inheritdoc />
        public virtual async Task DeleteAsync(TId id)
        {
            _traceWriter.LogMethodStart(new { id });

            if (_hookExecutor != null)
            {
                var resource = _resourceFactory.CreateInstance <TResource>();
                resource.Id = id;

                _hookExecutor.BeforeDelete(AsList(resource), ResourcePipeline.Delete);
            }

            var succeeded = await _repository.DeleteAsync(id);

            if (_hookExecutor != null)
            {
                var resource = _resourceFactory.CreateInstance <TResource>();
                resource.Id = id;

                _hookExecutor.AfterDelete(AsList(resource), ResourcePipeline.Delete, succeeded);
            }

            if (!succeeded)
            {
                AssertPrimaryResourceExists(null);
            }
        }
        public virtual async Task DeleteAsync(TId id)
        {
            _logger.LogTrace($"Entering {nameof(DeleteAsync)}('{id}').");

            if (_hookExecutor != null)
            {
                var resource = _resourceFactory.CreateInstance <TResource>();
                resource.Id = id;

                _hookExecutor.BeforeDelete(AsList(resource), ResourcePipeline.Delete);
            }

            var succeeded = await _repository.DeleteAsync(id);

            if (_hookExecutor != null)
            {
                var resource = _resourceFactory.CreateInstance <TResource>();
                resource.Id = id;

                _hookExecutor.AfterDelete(AsList(resource), ResourcePipeline.Delete, succeeded);
            }

            if (!succeeded)
            {
                AssertPrimaryResourceExists(null);
            }
        }
Ejemplo n.º 4
0
        public void AfterDelete <TResource, TId>(TId id)
            where TResource : class, IIdentifiable <TId>
        {
            var temporaryResource = _resourceFactory.CreateInstance <TResource>();

            temporaryResource.Id = id;

            _resourceHookExecutor.AfterDelete(temporaryResource.AsList(), ResourcePipeline.Delete, true);
        }
        public virtual async Task <bool> DeleteAsync(TId id)
        {
            var entity = (TResource)Activator.CreateInstance(typeof(TResource));

            entity.Id = id;
            if (!IsNull(_hookExecutor, entity))
            {
                _hookExecutor.BeforeDelete(AsList(entity), ResourcePipeline.Delete);
            }
            var succeeded = await _repository.DeleteAsync(entity.Id);

            if (!IsNull(_hookExecutor, entity))
            {
                _hookExecutor.AfterDelete(AsList(entity), ResourcePipeline.Delete, succeeded);
            }
            return(succeeded);
        }