예제 #1
0
        public async Task <CreateEntityTypeCommandResult> Handle(CreateEntityTypeCommand command, CancellationToken cancellationToken)
        {
            var type       = new EntityType(command.Entity.Name.ToLower(), command.Entity.Description);
            var entityType = await _unitOfWork.EntityTypeRepository.AddAsync(type);

            await _unitOfWork.SaveEntitiesAsync(cancellationToken);

            return(new CreateEntityTypeCommandResult(new EntityTypeWithIdentityDto
            {
                Id = entityType.Id,
                Name = entityType.Name,
                Description = entityType.Description
            }));
        }
예제 #2
0
        public async Task <CreateAttributeCommandResult> Handle(CreateAttributeCommand command, CancellationToken cancellationToken)
        {
            var attributeType = AttributeType.FromName(command.Attribute.Type.ToString());
            var attribute     = attributeType.CreateAttribute(command.Attribute.Name, command.Attribute.Description);

            var newAttribute = await _unitOfWork.AttributeRepository.AddAsync(attribute);

            await _unitOfWork.SaveEntitiesAsync(cancellationToken);

            return(new CreateAttributeCommandResult(new AttributeWithIdentityDto
            {
                Id = newAttribute.Id,
                Type = command.Attribute.Type,
                Name = command.Attribute.Name,
                Description = command.Attribute.Description
            }));
        }
예제 #3
0
        public async Task <DeleteEntityTypeCommandResult> Handle(DeleteEntityTypeCommand command, CancellationToken cancellationToken)
        {
            var attribute = await _unitOfWork.EntityTypeRepository.GetByIdAsync(command.Id);

            if (attribute == null)
            {
                return(new DeleteEntityTypeCommandResult(404, new [] { $"Not found entity type by id #{command.Id}" }));
            }

            await _unitOfWork.EntityTypeRepository.DeleteAsync(attribute);

            var result = await _unitOfWork.SaveEntitiesAsync(cancellationToken);

            return(new DeleteEntityTypeCommandResult(new ResultSuccessDto {
                Success = result
            }));
        }
예제 #4
0
        public async Task <UpdateAttributeCommandResult> Handle(UpdateAttributeCommand command, CancellationToken cancellationToken)
        {
            var attribute = await _unitOfWork.AttributeRepository.GetByIdAsync(command.Id);

            if (attribute == null)
            {
                return(new UpdateAttributeCommandResult(404, new[] { $"Attribute not found by #id {command.Id}" }));
            }

            attribute.ChangeName(command.Attribute.Name);
            attribute.ChangeDescription(command.Attribute.Name);

            var attributeUpdated = await _unitOfWork.AttributeRepository.UpdateAsync(attribute);

            await _unitOfWork.SaveEntitiesAsync(cancellationToken);

            return(new UpdateAttributeCommandResult(_mapper.Map <AttributeWithIdentityDto>(attributeUpdated)));
        }
예제 #5
0
        public async Task <CreateEntityCommandResult> Handle(CreateEntityCommand command, CancellationToken cancellationToken)
        {
            var entityType = await _unitOfWork.EntityTypeRepository.GetByNameAsync(command.Entity.Type);

            if (entityType == null)
            {
                return(new CreateEntityCommandResult(404, new [] { $"Not found entity type by name #{ command.Entity.Type}" }));
            }

            var attributes = await _unitOfWork.AttributeRepository.GetByNamesAsync(command.Entity.Attributes.Keys.ToArray());

            var entity = CreateEntity(entityType, attributes, command.Entity.Attributes);

            var newEntity = await _unitOfWork.EntityRepository.AddAsync(entity);

            await _unitOfWork.SaveEntitiesAsync(cancellationToken);

            return(new CreateEntityCommandResult(new GuidResultSuccessDto {
                Success = true, Id = newEntity.Id
            }));
        }