Exemple #1
0
        public async Task <IActionResult> SendMessage()
        {
            var greetingAsync = new GreetingAsyncEvent("Hello from the web");
            var greeting      = new GreetingEvent("Hello from the web");

            _context.Greetings.Add(greeting);
            _context.GreetingsAsync.Add(greetingAsync);

            await _context.SaveChangesAsync();

            _commandProcessor.Post(greeting);
            await _commandProcessor.PostAsync(greetingAsync);

            return(View("Index"));
        }
Exemple #2
0
        public override async Task <RemoveShipCommand> HandleAsync(RemoveShipCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = _contextFactory.Create())
            {
                var repository = new ShipRepositoryAsync(uow);
                await repository.DeleteAsync(command.ShipId, cancellationToken);

                await _commandProcessor.PostAsync(new ShipRemovedEvent(command.ShipId));
            }

            return(await base.HandleAsync(command, cancellationToken));
        }
        public override async Task <AddShippingLineCommand> HandleAsync(AddShippingLineCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = _contextFactory.Create())
            {
                var repository = new ShippingLineRepositoryAsync(uow);
                var line       = new ShippingLine(new Id(command.Id), command.LineName);
                await repository.AddAsync(line);

                await _commandProcessor.PostAsync(new NewLineAddedEvent(line.Id, line.LineName));
            }


            return(await base.HandleAsync(command, cancellationToken));
        }
        public override async Task<UpdateShipNameCommand> HandleAsync(UpdateShipNameCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = _contextFactory.Create())
            {
                var repository = new ShipRepositoryAsync(uow);
                var ship = await repository.GetAsync(command.ShipId, cancellationToken);
                if (ship == null) throw new NotFoundException($"Could not find a ship with Id {command.ShipId}");

                ship.ShipName = command.Name;

                await repository.UpdateAsync(ship, cancellationToken);

                await _commandProcessor.PostAsync(new ShipNameUpdatedEvent(ship.Id, command.Name, ship.Version));
            }
            
            return await base.HandleAsync(command, cancellationToken);
        }
        public override async Task <AddShipCommand> HandleAsync(AddShipCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = _contextFactory.Create())
            {
                var repo = new ShipRepositoryAsync(uow);
                var ship = new Ship(new Id(command.Id), command.Name, command.Type, command.Capacity, command.ShippingLine);

                await repo.AddAsync(ship);

                await _commandProcessor.PostAsync(
                    new NewShipAddedEvent(ship.Id, ship.ShipType, ship.ShipName, ship.Capacity, ship.ShippingLineId),
                    cancellationToken : cancellationToken
                    );
            }


            return(await base.HandleAsync(command, cancellationToken));
        }
Exemple #6
0
        public override async Task <UpdateLineNameCommand> HandleAsync(UpdateLineNameCommand command, CancellationToken cancellationToken = new CancellationToken())
        {
            using (var uow = _contextFactory.Create())
            {
                var repository = new ShippingLineRepositoryAsync(uow);
                var line       = await repository.GetAsync(command.LineId);

                if (line == null)
                {
                    throw new NotFoundException($"Could not find a line with the Id: {command.LineId}");
                }

                line.LineName = command.LineName;

                await repository.UpdateAsync(line);

                await _commandProcessor.PostAsync(new LineNameUpdatedEvent(line.Id, line.LineName, line.Version));
            }
            return(await base.HandleAsync(command, cancellationToken));
        }
Exemple #7
0
 public async Task PostAsync <T>(T request, bool continueOnCapturedContext = false, CancellationToken cancellationToken = default)
     where T : class, IRequest
 {
     await _commandProcessor.PostAsync(request, continueOnCapturedContext, cancellationToken);
 }