Ejemplo n.º 1
0
        public bool AddOrChangeBanknote(int denomination, long quantity)
        {
            BankDBEntities bankDBEntities = new BankDBEntities();

            try
            {
                var banknote = bankDBEntities.Banknotes.FirstOrDefault(b => b.Denomination == denomination);

                if (banknote != null)
                {
                    banknote.Quantity = quantity;
                }
                else
                {
                    bankDBEntities.Banknotes.Add(new Banknote {
                        Denomination = denomination, Quantity = quantity
                    });
                }

                bankDBEntities.SaveChanges();

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
            finally
            {
                bankDBEntities.Dispose();
            }
        }
Ejemplo n.º 2
0
 public BanknoteModel GetBanknote(int denomination)
 {
     using (BankDBEntities bankDBEntities = new BankDBEntities())
     {
         return(bankDBEntities.Banknotes
                .Where(b => b.Denomination == denomination)
                .ToArray()
                .Select(b => new BanknoteModel(b.Denomination, b.Quantity))
                .FirstOrDefault());
     }
 }
Ejemplo n.º 3
0
        public List <BanknoteModel> GetAllBanknotes()
        {
            List <BanknoteModel> banknotes = new List <BanknoteModel>();

            using (BankDBEntities bankDBEntities = new BankDBEntities())
            {
                foreach (var item in bankDBEntities.Banknotes)
                {
                    banknotes.Add(new BanknoteModel(item.Denomination, item.Quantity));
                }
            }

            return(banknotes);
        }