コード例 #1
0
        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);
            }
        }
コード例 #2
0
        /// <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);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public void BeforeDelete <TResource, TId>(TId id)
            where TResource : class, IIdentifiable <TId>
        {
            var temporaryResource = _resourceFactory.CreateInstance <TResource>();

            temporaryResource.Id = id;

            _resourceHookExecutor.BeforeDelete(temporaryResource.AsList(), ResourcePipeline.Delete);
        }
コード例 #5
0
        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);
        }