Beispiel #1
0
        private decimal GetOwnerPrice(int amount, BottleForPriceModel bottle)
        {
            var realAmount        = bottle.Amount_ml * (100 - bottle.WastePercent) / 100m;
            var numOfShotInBottle = realAmount / ShotSize_ml;
            var shotPrice         = bottle.BottlePrice / numOfShotInBottle;

            return(GetPrice(amount, shotPrice));
        }
Beispiel #2
0
        public decimal Run(TransactionForAdditionDto transaction, BottleForPriceModel bottle)
        {
            var usersSpecialPrice =
                bottle.SpecialPrices
                .FirstOrDefault(sp => sp.UserId == transaction.BuyerId);

            if (usersSpecialPrice is not null)
            {
                return(GetPrice(amount: transaction.Amount_ml.Value, shotPrice: usersSpecialPrice.Price));
            }

            var userIsOwner =
                bottle.Owners.Contains(transaction.BuyerId.Value);

            if (userIsOwner)
            {
                return(GetOwnerPrice(amount: transaction.Amount_ml.Value, bottle));
            }

            return(GetPrice(amount: transaction.Amount_ml.Value, bottle.ShotPrice));
        }