public void AdjustUnitCount(Guid stockId, Date date, int oldCount, int newCount, string comment, Guid transactionId) { var @event = new UnitCountAdjustmentOccurredEvent(Id, Version, transactionId, date, stockId, comment) { OriginalUnitCount = oldCount, NewUnitCount = newCount }; Apply(@event); PublishEvent(@event); }
public void Apply(UnitCountAdjustmentOccurredEvent @event) { var holding = _Holdings[@event.Stock]; if (holding == null) { throw new NoSharesOwnedException("No shares owned"); } var unitCountAdjustment = new UnitCountAdjustment { Id = @event.TransactionId, Date = @event.Date, Stock = holding.Stock, Comment = @event.Comment, OriginalUnits = @event.OriginalUnitCount, NewUnits = @event.NewUnitCount }; var handler = _TransactionHandlers.GetService <UnitCountAdjustment>(); handler.Apply(unitCountAdjustment, holding, _CashAccount); _Transactions.Add(unitCountAdjustment); }