Beispiel #1
0
        public async Task <IList <TDto> > Handle(BatchSaveCommand <TDto, TEntity, TKey> request, CancellationToken cancellationToken)
        {
            var addEntities    = _mapper.Map <IList <TEntity> >(request.AddList);
            var updateEntities = _mapper.Map <IList <TEntity> >(request.UpdateList);
            var deleteEntities = _mapper.Map <IList <TEntity> >(request.DeleteList);

            await _repository.AddRangeAsync(addEntities);

            foreach (var item in addEntities)
            {
                await _domainEventBus.PublishAsync(new CreatedEvent <TEntity>(item));
            }

            await _repository.UpdateRangeAsync(updateEntities);

            foreach (var item in updateEntities)
            {
                await _domainEventBus.PublishAsync(new ModifiedEvent <TEntity>(item));
            }

            await _repository.RemoveRangeAsync(deleteEntities);

            foreach (var item in deleteEntities)
            {
                await _domainEventBus.PublishAsync(new DeletedEvent <TEntity>(item));
            }

            var result = addEntities.Union(updateEntities);

            return(_mapper.Map <IList <TDto> >(result));
        }
        public async Task <FileItemDto> Handle(CreateCommand <FileItemCreateRequest, FileItemDto, FileItem, Guid> request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <FileItem>(request.Source);

            entity.CreationTime = DateTime.Now;

            HybridFileInfo fileInfo;

            do
            {
                entity.Path = PathHelper.NormalizePath(PathGenerator.GeneratePath(entity, _options));

                try
                {
                    fileInfo = await _fileManager.CreateFileFromStreamAsync(entity.Path, request.Source.FileStream);
                }
                catch (FileHasExistedException)
                {
                    throw;
                }
            } while (fileInfo == null);

            await _repository.AddAsync(entity);

            await _domainEventBus.PublishAsync(new CreatedEvent <FileItem>(entity));

            return(_mapper.Map <FileItemDto>(entity));
        }
        public async Task <TDto> Handle(CreateCommand <TCreateRequest, TDto, TEntity, TKey> request, CancellationToken cancellationToken)
        {
            var entity = _mapper.Map <TEntity>(request.Source);

            await _repository.AddAsync(entity);

            await _domainEventBus.PublishAsync(new CreatedEvent <TEntity>(entity));

            return(_mapper.Map <TDto>(entity));
        }
Beispiel #4
0
        public async Task <bool> Handle(DeleteCommand <TEntity, TKey> request, CancellationToken cancellationToken)
        {
            var entity = await _repository.FindByIdAsync(request.Source, cancellationToken);

            await _repository.RemoveAsync(entity);

            await _domainEventBus.PublishAsync(new DeletedEvent <TEntity>(entity));

            return(true);
        }
Beispiel #5
0
        public async Task <bool> Handle(BatchDeleteCommand <TEntity, TKey> request, CancellationToken cancellationToken)
        {
            var entities = await _repository.FindAsync(c => request.Source.Contains(c.Id), cancellationToken);

            await _repository.RemoveRangeAsync(entities, cancellationToken);

            foreach (var item in entities)
            {
                await _domainEventBus.PublishAsync(new DeletedEvent <TEntity>(item));
            }

            return(true);
        }
 public Task DispatchEventAsync <T>(T domainEvent) where T : IDomainEvent
 {
     return(_domainEventBus.PublishAsync(domainEvent));
 }