private async Task<PricingInfo> ProcessPriceChangesAsync(IOrder order, PriceInfoObject pricesInfoObject)
        {
            var criterias = _criteriaFactory.GetCriterias(order);
            if (!criterias.Any())
                return await Task.FromResult(new PricingInfo { Result = StatusEnum.Changed, Message = "Цена изменилась" });

            var oldPricesInfoObject = GetPricesInfo(order);

            var criteriaResultsTask = criterias.OrderBy(criteria => criteria.Priority).Select(criteria => new { criteria = criteria, Task = criteria.CheckCriteriaAsync(oldPricesInfoObject, pricesInfoObject) } ).ToList();
            await Task.WhenAll(criteriaResultsTask.Select(arg => arg.Task));

            var mostImportantCriteria = criteriaResultsTask.FirstOrDefault(arg => arg.Task.Exception==null && arg.Task.Result);
            if (mostImportantCriteria == null)
                throw new AggregateException(criteriaResultsTask.Select(arg => arg.Task.Exception));

            var makeDecisionTasks = _decisionFactory.GetDecisions(mostImportantCriteria.criteria).Select(decision => decision.ProcessDecisionAsync(order));
            await Task.WhenAll(makeDecisionTasks);

            return await Task.FromResult(new PricingInfo { Result = StatusEnum.Changed, Message = "Цена изменилась" });
        }
 public Task<bool> CheckCriteriaAsync(PriceInfoObject oldPriceInfo, PriceInfoObject newPriceInfo)
 {
     CheckCount++;
     return Task.FromResult(true);
 }
 private double CalculateDelta(IOrder order, PriceInfoObject pricesInfoObject)
 {
     return order.IsHotelBooked == false ?
         order.Price - pricesInfoObject.AviaPricesInfo.Price - pricesInfoObject.HotelPricesInfo.Price
         : order.Price - pricesInfoObject.AviaPricesInfo.Price;
 }