public async Task Handle(PaymentCompleted @event, CancellationToken cancellationToken)
        {
            var payment = await querySession.LoadAsync<Payment>(@event.PaymentId);

            var externalEvent = PaymentFinalized.Create(
                @event.PaymentId,
                payment!.OrderId,
                payment.Amount,
                @event.CompletedAt
            );

            await eventBus.Publish(externalEvent);
        }
Beispiel #2
0
    public async Task Handle(PaymentDiscarded @event, CancellationToken cancellationToken)
    {
        var payment = await querySession.LoadAsync <Payment>(@event.PaymentId, cancellationToken);

        var externalEvent = PaymentFailed.Create(
            @event.PaymentId,
            payment !.OrderId,
            payment.Amount,
            @event.DiscardedAt,
            PaymentFailReason.Discarded
            );

        await eventBus.Publish(externalEvent);
    }
Beispiel #3
0
 public async Task <IActionResult> GetBook(Guid Id)
 {
     using (IQuerySession session = this.DocumentStore.QuerySession())
     {
         return(Ok(await session.LoadAsync <Book>(Id)));
     }
 }
Beispiel #4
0
        public static async Task <SpecialUsages> Create(UserStarted started, IQuerySession session)
        {
            var user = await session.LoadAsync <User>(started.UserId);

            return(new SpecialUsages {
                UserName = user?.UserName
            });
        }
        public async Task <MyAggregate> Create(UserStarted @event, IQuerySession session, CancellationToken cancellation)
        {
            var user = await session.LoadAsync <User>(@event.UserId, cancellation);

            return(new MyAggregate
            {
                Created = user.UserName
            });
        }
Beispiel #6
0
        public static Task <User> get_user_id(
            string id,

            // Gets passed in by Jasper at runtime
            IQuerySession session,

            // Gets passed in by Jasper at runtime
            ILogger <User> logger)
        {
            logger.LogDebug("I loaded a user");
            return(session.LoadAsync <User>(id));
        }
Beispiel #7
0
        public async Task LoadByIdAsync(IQuerySession session, CancellationToken token = default(CancellationToken))
        {
            var userId = Guid.NewGuid();

            // Load a single document identified by a Guid
            var user = await session.LoadAsync <User>(userId, token);

            // There's an overload of Load for integers and longs
            var doc = await session.LoadAsync <IntDoc>(15, token);

            // Another overload for documents identified by strings
            var doc2 = await session.LoadAsync <StringDoc>("Hank", token);

            // Load multiple documents by a group of ids
            var users = await session.LoadManyAsync <User>(token, Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid());

            var ids = new Guid[] { Guid.NewGuid(), Guid.NewGuid(), Guid.NewGuid() };

            // If you already have an array of id values
            var users2 = await session.LoadManyAsync <User>(token, ids);
        }
Beispiel #8
0
        public async Task Handle(CartConfirmed @event, CancellationToken cancellationToken)
        {
            var cart = await querySession.LoadAsync <Cart>(@event.CartId, cancellationToken);

            var externalEvent = CartFinalized.Create(
                @event.CartId,
                cart.ClientId,
                cart.ProductItems.ToList(),
                cart.TotalPrice,
                @event.ConfirmedAt
                );

            await eventBus.Publish(externalEvent);
        }
Beispiel #9
0
        public async Task <ApplicationSettings> GetApplicationSettings(CancellationToken cancellationToken)
        {
            if (_memoryCache.TryGetValue(AppSettings, out ApplicationSettings? applicationSettings))
            {
                return(applicationSettings !);
            }

            using IQuerySession querySession = _documentStore.QuerySession();
            ApplicationSettingsData?applicationSettingsData =
                await querySession.LoadAsync <ApplicationSettingsData>(AppSettings, cancellationToken);

            applicationSettings = Map(applicationSettingsData ?? new ApplicationSettingsData());

            return(applicationSettings);
        }
        public async Task Apply(UserUpdated @event, MyAggregate aggregate, IQuerySession session)
        {
            var user = await session.LoadAsync <User>(@event.UserId);

            aggregate.UpdatedBy = user.UserName;
        }
Beispiel #11
0
 public static Task <User> get_user_id(string id, IQuerySession session)
 {
     return(session.LoadAsync <User>(id));
 }
Beispiel #12
0
 public Task <Issue> Get(Guid issueId)
 {
     return(_session.LoadAsync <Issue>(issueId));
 }
Beispiel #13
0
 public Task <User> get_user_id(string id)
 {
     _logger.LogDebug("I loaded a user");
     return(_session.LoadAsync <User>(id));
 }
Beispiel #14
0
 public Task <T> LoadAsync <T>(string id, CancellationToken token = new CancellationToken())
 {
     return(_querySession.LoadAsync <T>(id, token));
 }
Beispiel #15
0
 // SAMPLE: ResourceEndpoints
 public Task <Invoice> get_invoice_async(string invoiceId, IQuerySession session)
 {
     return(session.LoadAsync <Invoice>(invoiceId));
 }
Beispiel #16
0
 public Task <TSaga> Load(Guid correlationId)
 {
     return(_session.LoadAsync <TSaga>(correlationId));
 }