public virtual async Task <TResource> CreateAsync(TResource entity)
        {
            _logger.LogTrace($"Entering {nameof(CreateAsync)}(object).");

            entity = IsNull(_hookExecutor) ? entity : _hookExecutor.BeforeCreate(AsList(entity), ResourcePipeline.Post).SingleOrDefault();
            await _repository.CreateAsync(entity);

            entity = await GetWithRelationshipsAsync(entity.Id);

            if (!IsNull(_hookExecutor, entity))
            {
                _hookExecutor.AfterCreate(AsList(entity), ResourcePipeline.Post);
                entity = _hookExecutor.OnReturn(AsList(entity), ResourcePipeline.Get).SingleOrDefault();
            }
            return(entity);
        }
        public virtual async Task <TResource> CreateAsync(TResource entity)
        {
            entity = IsNull(_hookExecutor) ? entity : _hookExecutor.BeforeCreate(AsList(entity), ResourcePipeline.Post).SingleOrDefault();
            entity = await _repository.CreateAsync(entity);

            if (_includeService.Get().Any())
            {
                entity = await GetWithRelationshipsAsync(entity.Id);
            }

            if (!IsNull(_hookExecutor, entity))
            {
                _hookExecutor.AfterCreate(AsList(entity), ResourcePipeline.Post);
                entity = _hookExecutor.OnReturn(AsList(entity), ResourcePipeline.Get).SingleOrDefault();
            }
            return(entity);
        }
        /// <inheritdoc />
        public virtual async Task <TResource> CreateAsync(TResource resource)
        {
            _traceWriter.LogMethodStart(new { resource });
            if (resource == null)
            {
                throw new ArgumentNullException(nameof(resource));
            }

            if (_hookExecutor != null)
            {
                resource = _hookExecutor.BeforeCreate(AsList(resource), ResourcePipeline.Post).Single();
            }

            await _repository.CreateAsync(resource);

            resource = await GetPrimaryResourceById(resource.Id, true);

            if (_hookExecutor != null)
            {
                _hookExecutor.AfterCreate(AsList(resource), ResourcePipeline.Post);
                resource = _hookExecutor.OnReturn(AsList(resource), ResourcePipeline.Post).Single();
            }

            return(resource);
        }
        public virtual async Task <TResource> CreateAsync(TResource resource)
        {
            _logger.LogTrace($"Entering {nameof(CreateAsync)}(object).");

            if (_hookExecutor != null)
            {
                resource = _hookExecutor.BeforeCreate(AsList(resource), ResourcePipeline.Post).Single();
            }

            await _repository.CreateAsync(resource);

            resource = await GetPrimaryResourceById(resource.Id, true);

            if (_hookExecutor != null)
            {
                _hookExecutor.AfterCreate(AsList(resource), ResourcePipeline.Post);
                resource = _hookExecutor.OnReturn(AsList(resource), ResourcePipeline.Post).Single();
            }

            return(resource);
        }
示例#5
0
 public void OnReturnSingle <TResource>(TResource resource, ResourcePipeline pipeline)
     where TResource : class, IIdentifiable
 {
     _resourceHookExecutor.OnReturn(resource.AsList(), pipeline);
 }