// Apply the deltas to mutate our state
        private void Apply(LineItemAdded @event)
        {
            var price = @event.Price * (1 + @event.Vat / 100);

            Total += price;
            lines.Add(Tuple.Create(@event.Description, price, @event.Vat));
        }
Beispiel #2
0
        // Apply the deltas to mutate our state
        public void Apply(LineItemAdded @event)
        {
            var price = @event.Price * (1 + @event.Vat / 100);

            Total += price;
            lines.Add(Tuple.Create(@event.Description, price, @event.Vat));

            // Ensure to update version on every Apply method.
            Version++;
        }
Beispiel #3
0
        // Enforce any contracts on input, then raise event capturing the data
        public void AddLine(decimal price, decimal vat, string description)
        {
            if (string.IsNullOrEmpty(description))
            {
                throw new ArgumentException("Description cannot be empty", nameof(description));
            }

            var @event = new LineItemAdded(price, vat, description);

            // Call Apply to mutate state of aggregate based on event
            Apply(@event);

            // Add the event to uncommitted events to use it while persisting the events to Marten events store
            AddUncommittedEvent(@event);
        }