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

            var item = new Feedback(eventData.AggregateId)
            {
                Name            = eventData.Name,
                Description     = eventData.Description,
                OriginalVersion = eventData.Version
            };

            _writerRepository.Add(item);

            //Proportion
            if (_feedbackProportionRepository.GetById(eventData.AggregateId) != null)
            {
                throw new EventHandlerException($"Feedback proportion with id: {eventData.AggregateId} shouldn't exist", typeof(FeedbackAddedEventHandler));
            }

            var overallFeedbackAmount = _transactionRepository.GetAll()
                                        .Where(t => t is ISellingTransaction).Cast <ISellingTransaction>()
                                        .Sum(transaction => transaction.Feedback.Count());

            var proportion = new FeedbackProportion(eventData.AggregateId)
            {
                FeedbackShare = 0, OverallFeedbackAmount = overallFeedbackAmount
            };

            _feedbackProportionRepository.Add(proportion);
        }
예제 #2
0
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public IEnumerable <IAverageBuyingPrice> Execute(AverageBuyingPricesByStockIdQuery query)
        {
            var transactions = _modelReaderRepository
                               .GetAll()
                               .Where(t => t.Stock.Id.Equals(query.Id))
                               .OrderBy(t => t.OrderDate);

            return(_transactionCalculationService.CalculateAverageBuyingPrices(transactions));
        }
예제 #3
0
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public IEnumerable <string> Execute(StockTypeSearchQuery query)
        {
            var items = _modelReaderRepository.GetAll().Select(t => t.Type);

            if (!query.SearchTerm.Equals(" "))
            {
                items = items.Where(i => i.StartsWith(query.SearchTerm, StringComparison.InvariantCultureIgnoreCase));
            }

            return(items.Select(i => i).Distinct());
        }
예제 #4
0
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public IEnumerable <string> Execute(TransactionTagSearchQuery query)
        {
            var items = _modelReaderRepository.GetAll().Select(t => t.Tag);

            if (!query.SearchTerm.Equals(" "))
            {
                items = items.Where(i => i != null && i.StartsWith(query.SearchTerm, StringComparison.InvariantCultureIgnoreCase));
            }

            return(items.Select(i => i).Where(i => !string.IsNullOrEmpty(i)).Distinct());
        }
예제 #5
0
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public IEnumerable <string> Execute(StockTypeInUseSearchQuery query)
        {
            var transaction = _modelTransactionReaderRepository.GetAll();

            var items = _modelReaderRepository.GetAll()
                        .Join(transaction, t1 => t1.Id, t2 => t2.Stock.Id, (t1, t2) => t1).Select(t => t.Type);

            if (!query.SearchTerm.Equals(" "))
            {
                items = items.Where(i => i.StartsWith(query.SearchTerm, StringComparison.InvariantCultureIgnoreCase));
            }

            return(items.Select(i => i).Distinct());
        }
예제 #6
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <IStockStatistics> Execute(StockStatisticsAllQuery query)
 {
     return(_modelReaderRepository.GetAll().OrderByDescending(q => q.Performance));
 }
예제 #7
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IStock Execute(StockByWknQuery query)
 {
     return(_modelReaderRepository.GetAll().FirstOrDefault(s => s.Wkn.Equals(query.Wkn)));
 }
예제 #8
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <IStrategy> Execute(StrategyAllQuery query)
 {
     return(_modelReaderRepository.GetAll());
 }
예제 #9
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <int> Execute(TransactionYearsQuery query)
 {
     return(query.Filter(_modelReaderRepository.GetAll()).GroupBy(t => t.OrderDate.Year).OrderBy(t => t.Key).Select(t => t.Key));
 }
예제 #10
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <IAccountBalance> Execute(AccountBalanceAllQuery query)
 {
     return(_modelReaderRepository.GetAll().OrderByDescending(t => t.Date));
 }
예제 #11
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <IStock> Execute(StockAllQuery query)
 {
     return(_modelReaderRepository.GetAll().OrderBy(q => q.Name));
 }
예제 #12
0
        /// <summary>
        /// Executes the specified query.
        /// </summary>
        /// <param name="query">The query.</param>
        /// <returns></returns>
        public DateTime Execute(TransactionMinimumOrderDateQuery query)
        {
            var transactions = query.Filter(_modelReaderRepository.GetAll()).ToList();

            return(!transactions.Any() ? DateTime.MinValue : transactions.Min(t => t.OrderDate));
        }
예제 #13
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <string> Execute(TransactionTagAllQuery query)
 {
     return(_modelReaderRepository.GetAll().GroupBy(t => t.Tag).OrderBy(t => t.Key).Select(t => t.Key).Where(t => !string.IsNullOrEmpty(t)));
 }
예제 #14
0
        /// <summary>
        /// Processes the given event <paramref name="eventData"/>
        /// </summary>
        /// <param name="eventData">Event data</param>
        public void Handle(TransactionSellingOrderAddedEvent 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(TransactionSellingOrderAddedEventHandler));
            }

            var feedbacks = _feedbackRepository.GetAll().Where(f => eventData.Feedback.Contains(f.Id)).ToList();

            if (feedbacks == null)
            {
                throw new EventHandlerException("No Feedback found for the given ids", typeof(TransactionSellingOrderAddedEventHandler));
            }

            var item = new SellingTransaction(eventData.AggregateId)
            {
                OriginalVersion = eventData.Version,
                Description     = eventData.Description,
                Image           = eventData.Image,
                Feedback        = feedbacks,
                MAE             = eventData.MAE,
                MFE             = eventData.MFE,
                OrderCosts      = eventData.OrderCosts,
                OrderDate       = eventData.OrderDate,
                PricePerShare   = eventData.PricePerShare,
                Stock           = stock,
                Tag             = eventData.Tag,
                Taxes           = eventData.Taxes,
                Shares          = eventData.Shares,
                Action          = "Verkauf",
                PositionSize    = eventData.PositionSize
            };

            _writerRepository.Add(item);

            //Add to transaction book
            _transactionBook.AddEntry(new SellingTransactionBookEntry(
                                          eventData.StockId,
                                          eventData.AggregateId,
                                          eventData.OrderDate,
                                          eventData.Shares,
                                          eventData.PricePerShare,
                                          eventData.OrderCosts,
                                          eventData.Taxes));

            //Feedback Proportions
            var overallFeedbackAmount = _writerRepository.GetAll()
                                        .Where(t => t is ISellingTransaction).Cast <ISellingTransaction>()
                                        .Sum(transaction => transaction.Feedback.Count());


            foreach (var feedback in feedbacks)
            {
                var proportion = _feedbackProportionRepository.GetById(feedback.Id);

                proportion.FeedbackShare = _writerRepository
                                           .GetAll().Where(t => t is ISellingTransaction)
                                           .Cast <ISellingTransaction>()
                                           .SelectMany(t => t.Feedback)
                                           .Count(t => t.Id == feedback.Id);
            }

            foreach (var proportion in _feedbackProportionRepository.GetAll())
            {
                proportion.OverallFeedbackAmount = overallFeedbackAmount;
            }
        }
예제 #15
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <ICalculation> Execute(CalculationAllQuery query)
 {
     return(_modelReaderRepository.GetAll().OrderBy(q => q.Name));
 }
예제 #16
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <ITransactionPerformance> Execute(TransactionPerformanceAllQuery query)
 {
     return(_modelReaderRepository.GetAll());
 }
예제 #17
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <ITransaction> Execute(TransactionAllQuery query)
 {
     return(query.Filter(_modelReaderRepository.GetAll()).OrderByDescending(t => t.OrderDate));
 }
예제 #18
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <ITransaction> Execute(TransactionByStockIdQuery query)
 {
     return(_modelReaderRepository.GetAll().Where(t => t.Stock.Id.Equals(query.Id))
            .OrderByDescending(t => t.OrderDate));
 }
예제 #19
0
 /// <summary>
 /// Executes the specified query.
 /// </summary>
 /// <param name="query">The query.</param>
 /// <returns></returns>
 public IEnumerable <IFeedbackProportion> Execute(FeedbackProportionAllQuery query)
 {
     return(_modelReaderRepository.GetAll());
 }