Exemplo n.º 1
0
        public IEnumerable <IResult> Handle(CreateProduct request, IApplicationState state)
        {
            var guid = state.Query(NextGuid.Instance);
            var now  = state.Query(CurrentTime.Instance);

            var id      = new ProductId(guid);
            var product = new Product(id, request.Sku, now);

            yield return(InsertOne(db => db.Products, id, product));

            yield return(Publish(ProductCreated.Topic, new ProductCreated(id)));
        }
Exemplo n.º 2
0
        public async IAsyncEnumerable <IResult> HandleAsync(AddToBasket request, IApplicationState state)
        {
            var id  = state.Query(NextGuid.Instance);
            var now = state.Query(CurrentTime.Instance);

            yield return(this.LogDebug("Starting request {RequestId} at time {Timestamp}", id, now));

            var basket = await state.QueryAsync(new BasketById(request.Id));

            if (basket is null)
            {
                yield return(NotFound(request.Id));

                yield break;
            }

            yield return(UpdateOne(db => db.Baskets, request.Id, e => e with
            {
                Products = e.Products.Add(request.Product)
            }));