コード例 #1
0
        public Delivery Post([FromBody] Order order)
        {
            if (order != null && order.selectedDrinkCan != null &&
                order.selectedDrinkCan.ID > 0 && order.coinInserted != null && order.coinInserted.Count() > 0)
            {
                var giveBackMoney = new List <decimal>();
                var storage       = _coinStoreProvider.GetCoins();

                if (_moneyHandler.AreCoinsStorable(order.coinInserted.Select(c => c.Value).ToList(), storage.ToList()))
                {
                    List <decimal> moneyAvailable = _coinStoreProvider.GetAvailableMoney();
                    _moneyHandler.GiveBackMoney(order.selectedDrinkCan.Price, order.coinInserted.Sum(coin => coin.Value), giveBackMoney, moneyAvailable);

                    _coinStoreProvider.Update(order.coinInserted);
                    _coinStoreProvider.RemoveChange(giveBackMoney);
                    _drinkProvider.RemoveDrink(order.selectedDrinkCan);

                    return(new Delivery()
                    {
                        Drink = order.selectedDrinkCan,
                        Coins = giveBackMoney
                    });
                }

                return(new Delivery()
                {
                    ErrorMessage = "The capacity of coins of the machine has reached its maximum, we can't process your order"
                });
            }

            return(new Delivery()
            {
                ErrorMessage = "No coins have been inserted nor drink selected"
            });
        }
コード例 #2
0
 public IEnumerable <CoinStore> Get()
 {
     return(_coinProvider.GetCoins());
 }