public Task HandleAsync(StartNewGameCommand command, CancellationToken cancellationToken = new CancellationToken()) { var match = new Match(command.Id); match.Apply(command); return(_matchRepository.SaveAsync(match)); }
public async Task HandleAsync(ProcessTurnCommand command, CancellationToken cancellationToken = new CancellationToken()) { var currentMatch = await _matchRepository.GetByIdAsync(command.MatchId); if (currentMatch == null) { throw new ArgumentException("The match could not be found"); } currentMatch.Apply(command); await _matchRepository.SaveAsync(currentMatch, cancellationToken); }
// [CommandHandler] // To allow this method to be registered through attribute registration. public async Task HandleAsync(ActivateProductCommand command, CancellationToken cancellationToken = default(CancellationToken)) { Product product = await _productRepository.GetByIdAsync(command.ProductId); if (product == null) { throw new ProductNotFoundException("Product not found."); } product.Activate(); await _productRepository.SaveAsync(product); }
/// <summary> /// Save aggregate root and publish uncommitted domain events. /// </summary> /// <param name="aggregateRoot">Aggregate root.</param> /// <param name="cancellationToken">Cancellation token.</param> /// <returns>Asynchronous task.</returns> public async Task SaveAsync(TAggregateRoot aggregateRoot, CancellationToken cancellationToken = default(CancellationToken)) { // Get a copy of domain events marked for commit. IDomainEventStream domainEventsCopy = aggregateRoot.GetDomainEventsMarkedForCommit(); // Save aggregate root. await _decoratedRepository.SaveAsync(aggregateRoot); // Publish after saving. await _domainEventPublisher.PublishAsync(domainEventsCopy); // Clear domain events after publishing. aggregateRoot.MarkDomainEventsAsCommitted(); }
public async Task HandleAsync(CreateProductCommand command, ICorrelationContext context) { var product = new Product ( Guid.NewGuid(), command.Name, command.SupplierId, command.Count, command.PricePerUnit, command.SupplierId, command.CreatedDate, command.ExpirationDate, command.Description ); await _productRepository.SaveAsync(product, -1); }
public async Task HandleAsync(SubmitMovesCommand command, CancellationToken cancellationToken = new CancellationToken()) { if (!DeploymentCreditValidator.ValidDeployment(command.Deployments)) { throw new ArgumentException("Exceeded deployment credit allotment for move"); } var currentMatch = await _matchRepository.GetByIdAsync(command.Match); if (currentMatch == null) { throw new ArgumentException("The match could not be found"); } currentMatch.Apply(command); await _matchRepository.SaveAsync(currentMatch, cancellationToken); }
// [CommandHandler] // To allow this method to be registered through attribute registration. public Task HandleAsync(RegisterProductCommand command, CancellationToken cancellationToken = default(CancellationToken)) { return(_productRepository.SaveAsync(new Product(command.ProductId, command.ProductName))); }