예제 #1
0
        public bool ReturnCoinBudget(decimal value)
        {
            bool result = false;

            CoinBudget cbResult = _appDbContext.CoinBudgets.First(cb => cb.Value == value);

            if (cbResult != null && cbResult.Amount > 0)
            {
                cbResult.Amount--;
                result = true;
                _appDbContext.SaveChanges();
            }

            return(result);
        }
예제 #2
0
        public void AddCoinBudgets(IEnumerable <CoinBudget> coins)
        {
            foreach (CoinBudget coin in coins)
            {
                CoinBudget existingCB = _appDbContext.CoinBudgets.First <CoinBudget>(cb => cb.Value == coin.Value);
                if (existingCB == null)
                {
                    _appDbContext.CoinBudgets.Add(new CoinBudget()
                    {
                        Value = coin.Value, Amount = 1
                    });
                }
                else
                {
                    existingCB.Amount += coin.Amount;
                }
            }

            _appDbContext.SaveChanges();
        }