public async Task Consume(ConsumeContext <CreatePersonCommand> context)
        {
            ICallistoInsertOne <Domain.Person.Person> insertOperation = _operations.CreateInsertOperation(context.Message);
            CreatePersonResult dbResult = await _personCollection.InsertPerson(insertOperation);

            if (dbResult.Success)
            {
                await context.Publish <IPersonCreatedEvent>(new
                {
                    Result = dbResult
                });
            }

            await context.RespondAsync <IPersonCreatedEvent>(new
            {
                Result = dbResult
            });
        }
Example #2
0
        /// <summary>
        /// Insert one document into the collection.
        /// </summary>
        /// <param name="operation"><see cref="ICallistoInsertMany{T}"/></param>
        /// <returns>The inserted entities with id</returns>
        /// <exception cref="NullCallistoOperationException">When <see cref="ICallistoInsertOne{T}"/> is null</exception>
        /// <exception cref="NullOrEmptyValueException">When the values array is null or empty</exception>
        public async Task <TEntity> One(ICallistoInsertOne <TEntity> operation)
        {
            Helper.PreExecutionCheck(operation);
            if (operation.ClientSessionHandle is null)
            {
                await _collection.InsertOneAsync(operation.Value,
                                                 operation.InsertOneOptions,
                                                 operation.CancellationToken)
                .ConfigureAwait(false);

                return(operation.Value);
            }

            await _collection.InsertOneAsync(operation.ClientSessionHandle,
                                             operation.Value,
                                             operation.InsertOneOptions,
                                             operation.CancellationToken)
            .ConfigureAwait(false);

            return(operation.Value);
        }
        public async Task <CreatePersonResult> InsertPerson(ICallistoInsertOne <Person> insertOne)
        {
            await Operators.Insert.One(insertOne);

            return(CreatePersonResult.Create(insertOne.Value.Id));
        }