예제 #1
0
        public async Task CheckBid(IPriceProvider priceProvider)
        {
            if (IsEnded)
            {
                throw new CannotBidOnEndedGameException();
            }
            if (CurrentBid == null)
            {
                throw new NoActiveBidException();
            }
            if (CurrentBid.IsWon(await priceProvider.GetPrice()))
            {
                Produce(new BidWon(Id, CurrentBid.Amount));
            }
            else
            {
                await Emit(new BidLost(Id, CurrentBid.Amount));
            }

            if (TotalAmount <= 0)
            {
                Produce(new GameLost(Id));
            }
            if (TotalAmount >= WinAmount)
            {
                Produce(new GameWon(Id));
            }
        }
예제 #2
0
        public decimal Calculate(List <BasketItem> basketItems)
        {
            var discount    = _discounts.Sum(x => x.GetDiscount(basketItems));
            var basketTotal = basketItems.Sum(item => _priceProvider.GetPrice(item.Product) * item.Count);

            return(basketTotal - discount);
        }
예제 #3
0
        public double CalculateBasketPrice(Basket _basket)
        {
            var discounts = _basket.Items.SelectMany(x => x.GetDiscounts()).ToList();

            return(_basket.Items.Select(x =>
            {
                var discount = discounts.Where(y => y.ItemName == x.ItemName).ToList();

                if (discount != null && discount.Count > 0)
                {
                    return (_priceProvider.GetPrice(x.ItemName) * (x.ItemQty - discount.Count))
                    + (_priceProvider.GetPrice(x.ItemName) * discount.First().ReductionRate *discount.Count());
                }
                else
                {
                    return _priceProvider.GetPrice(x.ItemName) * x.ItemQty;
                }
            }).Sum() / 100);
        }
예제 #4
0
        public decimal GetDiscount(List <BasketItem> basketItem)
        {
            var milkPrice = _priceProvider.GetPrice(Products.Milk);

            var milkCount = basketItem
                            .Where(x => x.Product == Products.Milk)
                            .Sum(x => x.Count);

            return((milkCount / 4) * milkPrice);
        }
예제 #5
0
        public ISK GetPrice(TypeID typeId)
        {
            if (cache.ContainsKey(typeId))
            {
                return(cache[typeId]);
            }

            var result = baseProvider.GetPrice(typeId);

            cache[typeId] = result;
            return(result);
        }
예제 #6
0
        public decimal GetDiscount(List <BasketItem> basketItem)
        {
            var butterCount = basketItem
                              .Where(x => x.Product == Products.Butter)
                              .Sum(x => x.Count);

            var breadCount = basketItem
                             .Where(x => x.Product == Products.Bread)
                             .Sum(x => x.Count);

            var maxDiscountBreads = butterCount / 2;
            var discountedBreads  = breadCount > maxDiscountBreads ? maxDiscountBreads : breadCount;

            return(discountedBreads * _priceProvider.GetPrice(Products.Bread) / 2);
        }
예제 #7
0
        public async Task PlaceBid(Direction dir, decimal amount, IPriceProvider priceProvider)
        {
            if (IsEnded)
            {
                throw new CannotBidOnEndedGameException();
            }
            if (amount > TotalAmount)
            {
                throw new NotEnoughMoneyException();
            }
            if (CurrentBid != null)
            {
                throw new BidAlreadyPlacedException();
            }

            Produce(new BidPlaced(Id, dir, amount, await priceProvider.GetPrice()));
        }
예제 #8
0
        public void Scan(string name)
        {
            var price = _priceProvider.GetPrice(name);

            if (price != null)
            {
                if (_shoppingCart.TryGetValue(name, out var _))
                {
                    _shoppingCart[name].Count++;
                }
                else
                {
                    _shoppingCart.Add(name, new ShoppingCartItem {
                        Price = price, Count = 1
                    });
                }
            }
        }
예제 #9
0
        public static ISK GetPrice(this BPMaterial mat, IPriceProvider priceProvider)
        {
            var price = priceProvider.GetPrice(mat.matID).ToDecimal();

            return(price * mat.quantity * mat.damagePerJob);
        }
예제 #10
0
        public double GetYield(System.DateTime settlement, System.DateTime maturity, double rate, double pr, double redemption, int frequency, DayCountBasis basis = DayCountBasis.US_30_360)
        {
            var A = _couponProvider.GetCoupdaybs(settlement, maturity, frequency, basis);
            var N = _couponProvider.GetCoupnum(settlement, maturity, frequency, basis);
            var E = _couponProvider.GetCoupdays(settlement, maturity, frequency, basis);

            if (N <= -1)
            {
                var DSR    = E - A;
                var part1  = (redemption / 100 + rate / frequency) - (pr / 100d + (A / E * rate / frequency));
                var part2  = pr / 100d + (A / E) * rate / frequency;
                var retVal = part1 / part2 * ((frequency * E) / DSR);

                return(retVal);
            }
            else
            {
                double price   = pr;
                double fPriceN = 0.0;
                double fYield1 = 0.0;
                double fYield2 = 1.0;
                double fPrice1 = _priceProvider.GetPrice(settlement, maturity, rate, fYield1, redemption, frequency, basis);
                double fPrice2 = _priceProvider.GetPrice(settlement, maturity, rate, fYield2, redemption, frequency, basis);
                double fYieldN = (fYield2 - fYield1) * 0.5;


                for (int nIter = 0; nIter < 100 && !AreEqual(fPriceN, price); nIter++)
                {
                    fPriceN = _priceProvider.GetPrice(settlement, maturity, rate, fYieldN, redemption, frequency, basis);

                    if (AreEqual(price, fPrice1))
                    {
                        return(fYield1);
                    }
                    else if (AreEqual(price, fPrice2))
                    {
                        return(fYield2);
                    }
                    else if (AreEqual(price, fPriceN))
                    {
                        return(fYieldN);
                    }
                    else if (price < fPrice2)
                    {
                        fYield2 *= 2.0;
                        fPrice2  = _priceProvider.GetPrice(settlement, maturity, rate, fYield2, redemption, frequency, basis);

                        fYieldN = (fYield2 - fYield1) * 0.5;
                    }
                    else
                    {
                        if (price < fPriceN)
                        {
                            fYield1 = fYieldN;
                            fPrice1 = fPriceN;
                        }
                        else
                        {
                            fYield2 = fYieldN;
                            fPrice2 = fPriceN;
                        }

                        fYieldN = fYield2 - (fYield2 - fYield1) * ((price - fPrice2) / (fPrice1 - fPrice2));
                    }
                }
                if (System.Math.Abs(price - fPriceN) > price / 100d)
                {
                    throw new Exception("Result not precise enough");
                }
                return(fYieldN);
            }
        }
예제 #11
0
        public decimal GetPrice(DateTime date)
        {
            double value = Convert.ToDouble(provider.GetPrice(date));

            return(Convert.ToDecimal(value - (value * DiscountPercent)));
        }