//================================================================================
        public decimal GetAveragePrice(long transactionId, TransactionActionType actionType, long goodId, long unitId)
        {
            using (var dbContext = new InventoryDbContext())
            {
                var transactionItems = dbContext.TransactionItems.Where(
                    ti =>
                        ti.Transaction.Action == (byte)actionType &&
                        ti.TransactionId == transactionId && ti.GoodId == goodId &&
                        ti.Transaction.Status == (byte)TransactionStatus.FullPriced);

                if (transactionItems == null || transactionItems.Count() == 0)
                    throw new ObjectNotFound("FullPricedTransactionItems", transactionId);

                var transactionItemPrices = transactionItems.SelectMany(ti => ti.TransactionItemPrices);

                var totalTransactionQuantity = transactionItemPrices.Sum(tip => tip.QuantityAmount.Value);

                var totalTransactionPrice = transactionItemPrices.Sum(tip => tip.QuantityAmount.Value * tip.FeeInMainCurrency.Value);

                return totalTransactionPrice / totalTransactionQuantity;
            }
        }
Beispiel #2
0
 private AwardsTransaction(TransactionActionType type, decimal price)
 {
     Action = type;
     Price  = price;
 }