Exemplo n.º 1
0
        public HttpResponseMessage Create([FromBody] RegistreerDeelnemerCommand command)
        {
            var deelnemer = new PensioenSysteem.Domain.Deelnemer.Deelnemer();

            deelnemer.Registreer(command);
            _repo.Save(deelnemer, -1);
            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Exemplo n.º 2
0
        public async Task <Either <Error, Nothing> > Handle(CancellationToken cancelationToken, NonEmptyGuid id, Action <TAggregate> whatToDo)
        {
            var aggregate = await _aggregateStore.Load <TAggregate>(id, cancelationToken);

            whatToDo(aggregate);

            await _aggregateStore.Save(aggregate, cancelationToken);

            return(Nothing.Instance);
        }
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 async Task <PaymentId> CreatePayment(string cardNumber, int ccv, int expiryMonthDate, int expiryYearDate, double amount, Currency currency)
        {
            var card = CreditCard.Create(CardNumber.Create(cardNumber),
                                         ExpiryDate.Create(expiryMonthDate, expiryYearDate, _dateProvider),
                                         Ccv.Create(ccv));
            var money   = Money.Create(amount, currency);
            var payment = new Payment(PaymentId.Create(), card, money);

            await _paymentRepository.Save(payment);

            return(payment.Id);
        }
Exemplo n.º 5
0
        public async Task Save(IAggregate aggregate)
        {
            if (_aggregateTracking != null)
            {
                _aggregateTracking.TrackEvents(aggregate);
            }

            var orderedEvents = _aggregateRepository.Save(aggregate);

            foreach (var @event in orderedEvents)
            {
                await _eventListener.Handle(@event);
            }
        }
Exemplo n.º 6
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
            [Inject] IAggregateRepository repository,
            [Inject] IOrderHistory orderHistory,
            [Inject] ICustomerHistory customerHistory)
        {
            var dict = req.GetQueryParameterDictionary();

            var validator = new PlaceOrderValidator();

            var result = await validator.Validate(
                GetValueOrDefault("OrderNumber", dict),
                GetValueOrDefault("CustomerId", dict),
                orderHistory,
                customerHistory);

            if (!result.HasPassed)
            {
                return(new BadRequestObjectResult(result.Errors));
            }

            var order = new Order();

            order.Place(validator.CustomerId, validator.OrderNumber);
            await repository.Save(order);

            return(new OkObjectResult("Thanks for placing an order"));
        }
        protected override async Task HandleCore(UpdateTicketStatusCommand message)
        {
            var ticket = await _repository.Get <Ticket>(message.TicketId);

            ticket.UpdateStatus(message.StatusId, message.UserId);
            await _repository.Save(ticket);
        }
        public async Task Handle(AddTicketCommentCommand message)
        {
            var ticket = await _repository.Get <Ticket>(message.TicketId);

            ticket.AddComment(message.Comment, message.UserId);
            await _repository.Save(ticket);
        }
Exemplo n.º 9
0
        protected override async Task HandleCore(AddTicketCommentCommand message)
        {
            var ticket = await _repository.Get <Ticket>(message.TicketId);

            ticket.AddComment(message.Comment, message.UserId);
            await _repository.Save(ticket);
        }
Exemplo n.º 10
0
        protected override async Task HandleCore(UpdateTicketPriorityCommand message)
        {
            var ticket = await _repository.Get <Ticket>(message.TicketId);

            ticket.UpdatePriority(message.PriorityId, message.UserId);
            await _repository.Save(ticket);
        }
        public void Handle(RenameInventoryItem command)
        {
            var inventoryItem = _repository.GetById(command.InventoryItemId);

            inventoryItem.ChangeName(command.NewName);
            _repository.Save(inventoryItem);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        public void Execute(TransactionSplitCommand command)
        {
            if (command.Shares == 0)
            {
                throw new DomainValidationException("Shares", "Cannot sell zero units");
            }

            //TODO: Further Validation
            if (_book.GetOrAddOpenPosition(command.StockId).Shares == 0)
            {
                throw new DomainValidationException("Shares", "The amount of available shares cannot be zero for a split/reverse split.");
            }

            //Create new transaction
            var transaction = new TransactionAggregate();

            transaction.CreateSplitTransaction(
                command.AggregateId,
                command.OrderDate,
                command.Shares,
                command.PricePerShare,
                command.StockId);

            //Save transaction
            _repository.Save(transaction, -1);
        }
Exemplo n.º 13
0
        /// <summary>
        /// Executes the specified command.
        /// </summary>
        /// <param name="command">The command.</param>
        /// <returns></returns>
        public void Execute(TransactionDividendCommand command)
        {
            if (command.Shares == 0)
            {
                throw new DomainValidationException("Shares", "Cannot sell zero units");
            }

            //TODO: Further Validation
            if (_book.GetOrAddOpenPosition(command.StockId).Shares < command.Shares)
            {
                throw new DomainValidationException("Shares", "The amount of available units for the stock is smaller than those used in the dividend.");
            }

            //Create new transaction
            var transaction = new TransactionAggregate();

            transaction.CreateDividendTransaction(
                command.AggregateId,
                command.OrderDate,
                command.Shares,
                command.PricePerShare,
                command.OrderCosts,
                command.Description,
                command.Tag,
                command.Image,
                command.StockId,
                command.Taxes);

            //Save transaction
            _repository.Save(transaction, -1);
        }
        public async Task Consume(ConsumeContext <CreateArticle> context)
        {
            var article = _aggregateRepository.Get <Domain.Article>(context.Message.Id);

            article.Create(context.Message);
            _aggregateRepository.Save(article);
            await Console.Out.WriteLineAsync($"Article Created : {context.Message.ToJson()}");
        }
Exemplo n.º 15
0
        public HttpResponseMessage Create([FromBody] RegistreerWerkgeverCommand command)
        {
            var werkgever = new PensioenSysteem.Domain.Werkgever.Werkgever();

            werkgever.Registreer(command);
            _repo.Save(werkgever, -1);
            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
        public HttpResponseMessage Create([FromBody] RegistreerArbeidsverhoudingCommand command)
        {
            var arbeidsverhouding = new PensioenSysteem.Domain.Arbeidsverhouding.Arbeidsverhouding();

            arbeidsverhouding.Registreer(command);
            _repo.Save(arbeidsverhouding, -1);
            return(new HttpResponseMessage(HttpStatusCode.Created));
        }
Exemplo n.º 17
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.º 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(StrategyRemoveCommand command)
        {
            var aggregate = _repository.GetById(command.AggregateId);

            aggregate.Remove();

            _repository.Save(aggregate, command.OriginalVersion);
        }
Exemplo n.º 19
0
        public static Task Save(
            [NotNull] this IAggregateRepository repository,
            IAggregate aggregate,
            Guid commitId)
        {
            Ensure.That(repository, "repository").IsNotNull();

            return(repository.Save(aggregate, commitId, a => { }, CancellationToken.None));
        }
Exemplo n.º 20
0
        public async Task Should_persist_an_aggregate_with_100_events()
        {
            // Arrange
            var car = new Car(_carId);

            for (var i = 1; i <= 100; i++)
            {
                car.Travel(i);
            }

            // Act
            await _repository.Save(car);

            var savedModel = await _repository.Get(_carId);

            // Assert
            savedModel.Should().BeEquivalentTo(car);
        }
Exemplo n.º 21
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);
        }
        public void Execute(TCommand command)
        {
            var agg = _aggRepository.Get(command.Id);

            (agg as IAggHandleCommand <TCommand>).Execute(command);
            var events = agg.GetUncommittedChanges();

            _aggRepository.Save(agg.Id, events, command.AggregateVersion);
            _eventPublisher.PublishEvents(events);
        }
Exemplo n.º 23
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.º 24
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.º 25
0
        public async Task Handle(CreateSchemaCommand command)
        {
            // Define id for the new schema (assume the id doesn't exist yet)
            Guid gSchemaId = Guid.NewGuid();

            // create schema
            var schema = new Schema(gSchemaId);

            // set name
            schema.Rename(command.Name);

            // add properties
            foreach (var property in command.Properties)
            {
                schema.AddProperty(property);
            }

            // save
            await _repository.Save(schema);
        }
Exemplo n.º 26
0
        public static Task Save(
            [NotNull] this IAggregateRepository repository,
            string bucketId,
            IAggregate aggregate,
            Guid commitId,
            CancellationToken cancellationToken)
        {
            Ensure.That(repository, "repository").IsNotNull();

            return(repository.Save(aggregate, bucketId, commitId, a => { }, cancellationToken));
        }
Exemplo n.º 27
0
        public static Task Save(
            [NotNull] this IAggregateRepository repository,
            IAggregate aggregate,
            Guid commitId,
            Action <IDictionary <string, object> > updateHeaders,
            CancellationToken cancellationToken)
        {
            Ensure.That(repository, "repository").IsNotNull();

            return(repository.Save(aggregate, DefaultBucket, commitId, updateHeaders, cancellationToken));
        }
Exemplo n.º 28
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.º 29
0
        private static async Task CancelOrder(IAggregateRepository repository, ILogger log, OrderPlaced @event)
        {
            var order = await repository.Load <Order>(@event.OrderId);

            log.LogInformation("The customer cancelled");
            if (order != null)
            {
                order.Cancel("Customer requested cancellation");
                await repository.Save(order);
            }
        }
Exemplo n.º 30
0
        /// <summary>
        /// Finds or creates a new aggregate if it doesn't exist, runs the update handler and saves it.
        /// </summary>
        /// <typeparam name="T">Type of the aggregate</typeparam>
        /// <param name="repository">repository instance</param>
        /// <param name="id">the aggregate id</param>
        /// <param name="handler">the create/update handler</param>
        /// <returns>A Task containing the created or updated aggregate</returns>
        public static async Task <T> CreateOrUpdate <T>(this IAggregateRepository <T> repository, string id, Action <T> handler)
            where T : IAggregate
        {
            var aggregate = await repository.FindOrDefault(id);

            handler(aggregate);

            await repository.Save(aggregate);

            return(aggregate);
        }
        private async Task SaveAndTest(IAggregateRepository<IHomogeneousRole<RoleIdentifier>, RoleIdentifier> repo, params IHomogeneousRole<RoleIdentifier>[] roles)
        {
            foreach (var role in roles)
                await repo.Save(role);

            foreach (var role in roles)
            {
                var reconstituted = await repo.Get(role.Id);

                reconstituted.Should().NotBeNull();
                reconstituted.Should().NotBeSameAs(role);
                reconstituted.Id.Should().Be(role.Id);
                reconstituted.Version.Should().Be(role.Version);
                reconstituted.Name.Should().Be(role.Name);
                reconstituted.Status.Should().Be(role.Status);
            }
        }