Exemplo n.º 1
0
        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 }));
        }
Exemplo n.º 3
0
        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 }));
        }
Exemplo n.º 6
0
        /// <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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        /// <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);
        }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
        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));
        }
Exemplo n.º 14
0
        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));
        }
Exemplo n.º 15
0
        /// <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);
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        /// <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);
        }
Exemplo n.º 18
0
        /// <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);
        }
Exemplo n.º 21
0
        public Domain.Werkgever.Werkgever Get(Guid id)
        {
            var werkgever = _repo.GetById(id);

            return(werkgever);
        }
Exemplo n.º 22
0
 public T GetById <T>(Guid aggregateId) where T : IAggregate
 {
     return(_aggregateRepository.GetById <T>(aggregateId));
 }