Beispiel #1
0
        //выписка движение по счету
        public IEnumerable <TransactionData> Movement(int accountNo)
        {
            using (AccountEntities db = new AccountEntities())
            {
                if (db.accounts.Any(a => a.account == accountNo))
                {
                    int accId    = db.accounts.First(a => a.account == accountNo).id;
                    var movement = db.transactions.
                                   Where(t => t.accId == accId).
                                   OrderBy(t => t.transDate).ToList();

                    List <TransactionData> result = new List <TransactionData>();

                    foreach (var t in movement)
                    {
                        result.Add(new TransactionData {
                            transDate = t.transDate, transAmount = t.transAmount
                        });
                    }

                    return(result);
                }
                else
                {
                    throw new ArgumentException();
                }
            }
        }
Beispiel #2
0
 //определение, существует ли в базе счет с данным номером
 public bool AccountExists(int accountNo)
 {
     using (AccountEntities db = new AccountEntities())
     {
         return(db.accounts.Any(a => a.account == accountNo));
     }
 }
Beispiel #3
0
 //баналс по счету с данным номером
 public decimal Balance(int accountNo)
 {
     using (AccountEntities db = new AccountEntities())
     {
         if (db.accounts.Any(a => a.account == accountNo))
         {
             return(db.accounts.First(a => a.account == accountNo).balance);
         }
         else
         {
             throw new ArgumentException();
         }
     }
 }
Beispiel #4
0
 public void Delete(int accountNo)
 {
     using (AccountEntities db = new AccountEntities())
     {
         if (db.accounts.Any(a => a.account == accountNo))
         {
             accounts account = db.accounts.First(a => a.account == accountNo);
             db.accounts.Remove(account);
             db.SaveChanges();
         }
         else
         {
             throw new ArgumentException();
         }
     }
 }
Beispiel #5
0
 public void Create(int accountNo)
 {
     using (AccountEntities db = new AccountEntities())
     {
         if (!db.accounts.Any(a => a.account == accountNo))
         {
             accounts account = new accounts {
                 account = accountNo, balance = 0
             };
             db.accounts.Add(account);
             db.SaveChanges();
         }
         else
         {
             throw new ArgumentException();
         }
     }
 }
Beispiel #6
0
 public void Change(int accountNo, decimal sum)
 {
     using (AccountEntities db = new AccountEntities())
     {
         if (db.accounts.Any(a => a.account == accountNo))
         {
             accounts     account     = db.accounts.First(a => a.account == accountNo);
             transactions transaction = new transactions {
                 accounts = account, transAmount = sum, transDate = DateTime.Now
             };
             db.transactions.Add(transaction);
             db.SaveChanges();
         }
         else
         {
             throw new ArgumentException();
         }
     }
 }