Beispiel #1
0
        public async Task <Unit> Handle(MakeTransfer command, CancellationToken cancellationToken = default)
        {
            var(fromAccountId, toAccountId, amount) = command;
            var accountFrom = await Store.AggregateStreamAsync <Account>(fromAccountId, token : cancellationToken)
                              ?? throw AggregateNotFoundException.For <Account>(fromAccountId);

            accountFrom.RecordOutflow(toAccountId, amount);

            var accountFromEvents = accountFrom.DequeueUncommittedEvents();

            Store.Append(accountFrom.Id, accountFromEvents);

            var accountTo = await Store.AggregateStreamAsync <Account>(toAccountId, token : cancellationToken)
                            ?? throw AggregateNotFoundException.For <Account>(toAccountId);

            accountTo.RecordInflow(fromAccountId, amount);

            var accountToEvents = accountFrom.DequeueUncommittedEvents();

            Store.Append(accountTo.Id, accountTo);

            await session.SaveChangesAsync(cancellationToken);

            await eventBus.Publish(accountFromEvents);

            await eventBus.Publish(accountToEvents);

            return(Unit.Value);
        }
Beispiel #2
0
    public async Task <Unit> Handle(ConfirmReservation command, CancellationToken cancellationToken)
    {
        var reservation = await repository.Find(command.ReservationId, cancellationToken)
                          ?? throw AggregateNotFoundException.For <Reservation>(command.ReservationId);

        reservation.Confirm();

        await repository.Update(reservation, cancellationToken);

        return(Unit.Value);
    }
Beispiel #3
0
        public async Task <Unit> Handle(ScheduleMeeting request, CancellationToken cancellationToken)
        {
            var meeting = await repository.Find(request.MeetingId, cancellationToken)
                          ?? throw AggregateNotFoundException.For <Meeting>(request.MeetingId);

            meeting.Schedule(request.Occurs);

            await repository.Update(meeting, cancellationToken);

            return(Unit.Value);
        }
        public async Task <Unit> Handle(ScheduleMeeting command, CancellationToken cancellationToken)
        {
            var(meetingId, dateRange) = command;

            var meeting = await repository.Find(meetingId, cancellationToken)
                          ?? throw AggregateNotFoundException.For <Meeting>(meetingId);

            meeting.Schedule(dateRange);

            await repository.Update(meeting, cancellationToken);

            return(Unit.Value);
        }
Beispiel #5
0
        public async Task <Unit> Handle(CancelReservation command, CancellationToken cancellationToken)
        {
            Guard.Against.Null(command, nameof(command));

            var reservation = await repository.Find(command.ReservationId, cancellationToken)
                              ?? throw AggregateNotFoundException.For <Reservation>(command.ReservationId);

            reservation.Cancel();

            await repository.Update(reservation, cancellationToken);

            return(Unit.Value);
        }
Beispiel #6
0
    public async Task Handle(CartConfirmed @event, CancellationToken cancellationToken)
    {
        var cart = await querySession.LoadAsync <Cart>(@event.CartId, cancellationToken)
                   ?? throw  AggregateNotFoundException.For <Cart>(@event.CartId);

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

        await eventBus.Publish(externalEvent);
    }
    public async Task <CartDetails> Handle(GetCartAtVersion request, CancellationToken cancellationToken)
    {
        var cart = await eventStore.AggregateStream <CartDetails>(
            request.CartId,
            cancellationToken,
            request.Version
            );

        if (cart == null)
        {
            throw AggregateNotFoundException.For <Cart>(request.CartId);
        }

        return(cart);
    }