protected async Task HandleCommand <TCommand>(TCommand command, Func <TAggregateRoot, TCommand, IEnumerable <Event <TAggregateIdentity> > > handler, Func <IEnumerable <Event <TAggregateIdentity> >, Task> dispatchEvents) where TCommand : Command <TAggregateIdentity> { var isAlreadyProcessed = await _idempotencyCheck.IsProcessed(command.Id).ConfigureAwait(false); if (isAlreadyProcessed) { return; } var aggregateRoot = await _aggregateRepository .GetById <TAggregateRoot, TAggregateIdentity>(command.AggregateIdentity).ConfigureAwait(false); var events = handler(aggregateRoot, command); foreach (var @event in events) { aggregateRoot.PlayEvent(@event, true); } await _aggregateRepository.Store <TAggregateRoot, TAggregateIdentity>(aggregateRoot).ConfigureAwait(false); await dispatchEvents(events).ConfigureAwait(false); await _idempotencyCheck.MarkProcessed(command.Id).ConfigureAwait(false); }
public async Task <IActionResult> Put(Guid retrospectiveId, string participantId) { var retro = await _aggRepo.GetById <Retrospective>(retrospectiveId); var cmd = new AddParticipant(retrospectiveId, participantId); await _cmdSender.Send(cmd); return(RedirectToAction("Get", new { retrospectiveId = retrospectiveId })); }
public async Task Handle(AddShip command) { var aggregateGame = await _store.GetById <Game>(command.GameId); if (aggregateGame.AddShip(command.ShipDetails, command.PlayerIndex)) { // ship was added, persist aggregate await _store.Save(aggregateGame, aggregateGame.Version); } }
public void Handle(RenameInventoryItem command) { var inventoryItem = _repository.GetById(command.InventoryItemId); inventoryItem.ChangeName(command.NewName); _repository.Save(inventoryItem); }
public async Task <IActionResult> FireShot(Guid gameId, uint attackingPlayerIndex, uint targetPlayer, char row, uint column, int gameVersion) { var game = await _aggRepo.GetById <Game>(gameId); var location = new Location(row, column); // See if user inputs are valid if (!game.ValidLocation(location, targetPlayer)) { return(new BadRequestResult()); } await _bus.Send(new FireShot(Guid.NewGuid(), gameVersion, gameId, new Location(row, column), attackingPlayerIndex, targetPlayer)); return(new RedirectToActionResult("Get", "Games", new { gameId })); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> /// <exception cref="DomainValidationException">Thrown if validation fails</exception> public void Execute(StrategyRemoveCommand command) { var aggregate = _repository.GetById(command.AggregateId); aggregate.Remove(); _repository.Save(aggregate, command.OriginalVersion); }
public virtual async Task Handle(TCommand command, CancellationToken cancellationToken) { var aggregateId = command.GetAggregateId(); var aggregate = await _aggregateRepository.GetById <TAggregate>(aggregateId, cancellationToken); HandleCommand(aggregate, command); await _aggregateRepository.Save(aggregate, cancellationToken); }
public static Task <TAggregate> GetById <TAggregate>( [NotNull] this IAggregateRepository repository, string id) where TAggregate : class, IAggregate { Ensure.That(repository, "repository").IsNotNull(); return(repository.GetById <TAggregate>(DefaultBucket, id, int.MaxValue, CancellationToken.None)); }
public HttpResponseMessage Verhuis(Guid id, [FromBody] VerhuisDeelnemerCommand command) { Domain.Deelnemer.Deelnemer deelnemer; try { deelnemer = _repo.GetById(id); } catch (AggregateNotFoundException ex) { return(new HttpResponseMessage(HttpStatusCode.NotFound)); } deelnemer.Verhuis(command); _repo.Save(deelnemer, command.Version); return(new HttpResponseMessage(HttpStatusCode.OK)); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> /// <exception cref="DomainValidationException">Thrown if validation fails</exception> public void Execute(FeedbackChangeCommand command) { var aggregate = _repository.GetById(command.AggregateId); aggregate.ChangeName(command.Name); aggregate.ChangeDescription(command.Description); _repository.Save(aggregate, command.OriginalVersion); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> public void Execute(TransactionRemoveCommand command) { //TODO: Validation var aggregate = _repository.GetById(command.AggregateId); aggregate.Undo(); _repository.Save(aggregate, command.OriginalVersion); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> /// <exception cref="DomainValidationException">Thrown if validation fails</exception> public void Execute(CalculationCopyCommand command) { var aggregate = _repository.GetById(command.OriginalId); var copy = new CalculationAggregate(); copy.Copy(aggregate, command.AggregateId); _repository.Save(copy, -1); }
public static Task <TAggregate> GetById <TAggregate>( [NotNull] this IAggregateRepository repository, string bucketId, Guid id, CancellationToken cancellationToken) where TAggregate : class, IAggregate { Ensure.That(repository, "repository").IsNotNull(); return(repository.GetById <TAggregate>(bucketId, id, int.MaxValue, cancellationToken)); }
public static Task <TAggregate> GetById <TAggregate>( [NotNull] this IAggregateRepository repository, Guid id, int version, CancellationToken cancellationToken) where TAggregate : class, IAggregate { Ensure.That(repository, "repository").IsNotNull(); return(repository.GetById <TAggregate>(DefaultBucket, id, version, cancellationToken)); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> /// <exception cref="DomainValidationException">Thrown if validation fails</exception> public void Execute(StockChangeCommand command) { var aggregate = _repository.GetById(command.AggregateId); aggregate.ChangeName(command.Name); aggregate.ChangeLongShort(command.LongShort); aggregate.ChangeType(command.Type); aggregate.ChangeWkn(command.Wkn); _repository.Save(aggregate, command.OriginalVersion); }
public T GetById <T>(Guid aggregateId) where T : IAggregate { if (_aggregateCache != null) { if (_aggregateCache.TryGet <T>(aggregateId, out var aggregate)) { return(aggregate); } } return(_aggregateRepository.GetById <T>(aggregateId)); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> /// <exception cref="DomainValidationException">Thrown if validation fails</exception> public void Execute(StockQuotationAddOrChangeCommand command) { if (command.Quotation == null) { throw new DomainValidationException("command.Quotation", "Quotation has no value"); } var aggregate = _repository.GetById(command.AggregateId); aggregate.AddOrChangeQuotation(command.Quotation); _repository.Save(aggregate, command.OriginalVersion); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> /// <exception cref="DomainValidationException">Thrown if validation fails</exception> public void Execute(CalculationChangeCommand command) { var aggregate = _repository.GetById(command.AggregateId); aggregate.ChangeName(command.Name); aggregate.ChangeWkn(command.Wkn); aggregate.ChangeMultiplier(command.Multiplier); aggregate.ChangeStrikePrice(command.StrikePrice); aggregate.ChangeUnderlying(command.Underlying); aggregate.ChangeInitialSl(command.InitialSl); aggregate.ChangeInitialTp(command.InitialTp); aggregate.ChangePricePerUnit(command.PricePerUnit); aggregate.ChangeOrderCosts(command.OrderCosts); aggregate.ChangeDescription(command.Description); aggregate.ChangeUnits(command.Units); aggregate.ChangeIsLong(command.IsLong); _repository.Save(aggregate, command.OriginalVersion); }
public Domain.Arbeidsverhouding.Arbeidsverhouding Get(Guid id) { var arbeidsverhouding = _repo.GetById(id); return(arbeidsverhouding); }
public async Task Handle(AddActionItem command) { var retrospective = await _store.GetById <Retrospective>(command.RetrospectiveId); retrospective.AddActionItem(command.Description, command.ParticipantId); await _store.Save(retrospective, retrospective.Version); }
public Domain.Werkgever.Werkgever Get(Guid id) { var werkgever = _repo.GetById(id); return(werkgever); }
public T GetById <T>(Guid aggregateId) where T : IAggregate { return(_aggregateRepository.GetById <T>(aggregateId)); }