Beispiel #1
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionBuyingOrderAddedEvent eventData)
        {
            if (_writerRepository.GetById(eventData.AggregateId) != null)
            {
                return;
            }

            var stock = _stockRepository.GetById(eventData.StockId);

            if (stock == null)
            {
                throw new EventHandlerException($"No Stock found with id: {eventData.StockId}", typeof(TransactionBuyingOrderAddedEventHandler));
            }

            var strategy = _strategyRepository.GetById(eventData.StrategyId);

            if (strategy == null)
            {
                throw new EventHandlerException($"No Strategy found with id: {eventData.StrategyId}", typeof(TransactionBuyingOrderAddedEventHandler));
            }

            var item = new BuyingTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                Description     = eventData.Description,
                Image           = eventData.Image,
                InitialSL       = eventData.InitialSL,
                InitialTP       = eventData.InitialTP,
                OrderCosts      = eventData.OrderCosts,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Strategy        = strategy,
                Tag             = eventData.Tag,
                Shares          = eventData.Shares,
                Action          = "Kauf",
                PositionSize    = eventData.PositionSize,
                CRV             = eventData.CRV
            };

            _writerRepository.Add(item);

            //Add to transaction book
            _transactionBook.AddEntry(new BuyingTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare,
                                          eventData.OrderCosts));
        }
 private Domain.Layer.Transactions.BuyingTransaction MapData(BuyingTransaction data)
 {
     return(new Domain.Layer.Transactions.BuyingTransaction()
     {
         ProductId = (short)data.ProductId,
         PurchasedDate = data.PurchasedDate,
         PurchasedPrice = (decimal)data.PurchasedPrice,
         PurchasedQuantity = (decimal)data.PurchasedQuantity,
         PurchasedRatePerGram = (decimal)data.PurchasedRatePerGram,
         PurchasedTax = (decimal)data.PurchasedTax,
         PurchasedTotalPrice = (decimal)data.PurchasedTotalPrice,
         PurchasedTransactionId = (long)data.PurchasedTransactionId,
         UserId = (int)data.UserId,
     });
 }
 public IHttpActionResult CreateBuyingTransaction(BuyingTransaction buyingTransaction)
 {
     transactions = new TransactionsOrc();
     return(Ok(transactions.CreateBuyingTransaction(buyingTransaction)));
 }