/// <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); }
/// <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); }
/// <summary> /// Executes the specified command. /// </summary> /// <param name="command">The command.</param> /// <returns></returns> public void Execute(TransactionSellCommand command) { if (command.Shares == 0) { throw new DomainValidationException("Units", "Cannot sell zero units"); } //TODO: Further Validation if (_book.GetOrAddOpenPosition(command.StockId).Shares < command.Shares) { throw new DomainValidationException("Units", "The amount of available units for the stock is smaller than those sold."); } //TODO: Validation MAE must be smaller than share price if long, else higher, same for MFE //Create new transaction var transaction = new TransactionAggregate(); transaction.CreateSellingTransaction( command.AggregateId, command.OrderDate, command.Shares, command.PricePerShare, command.OrderCosts, command.Description, command.Tag, command.Image, command.StockId, command.Taxes, command.MAE, command.MFE, command.Feedback); //Save transaction _repository.Save(transaction, -1); }