Exemplo n.º 1
0
        public int WithdrawalAmount(SavingsTransactionEntity s, String AccountID)
        {
            var res = from c in ob.SavingsAccounts
                      where c.AccountId == AccountID
                      select c;

            if (res == null)
            {
                return(0);
            }
            else
            {
                string transid;
                var    lasttransID = ob.SavingsTransactions.OrderByDescending(t => t.TransactionId).FirstOrDefault();
                if (lasttransID == null)
                {
                    transid = "00001";
                }
                else
                {
                    transid = (Convert.ToInt32(lasttransID.TransactionId) + 1).ToString();
                }
                var amount = ob.SavingsAccounts.OrderByDescending(t => t.Balance).Where(f => f.AccountId == AccountID).FirstOrDefault();
                if (s.Amount <= (Convert.ToInt32(amount.Balance)))
                {
                    SavingsTransaction st = new SavingsTransaction()
                    {
                        TransactionId = Int32.Parse(transid), AccountId = AccountID, TransactionDate = DateTime.Now, TransactionType = "W", Amount = s.Amount
                    };
                    (from p in ob.SavingsAccounts
                     where p.AccountId == AccountID
                     select p).ToList().ForEach(x => x.Balance = x.Balance - s.Amount);
                    ob.SavingsTransactions.Add(st);
                    return(ob.SaveChanges());
                }
                else
                {
                    return(-1);
                }
            }
        }
Exemplo n.º 2
0
 public int DepositAmount(SavingsTransactionEntity s, String AccountID)
 {
     try
     {
         var res = from c in ob.SavingsAccounts
                   where c.AccountId == AccountID
                   select c;
         if (res == null)
         {
             return(0);
         }
         else
         {
             string transid;
             var    lasttransID = ob.SavingsTransactions.OrderByDescending(t => t.TransactionId).FirstOrDefault();
             if (lasttransID == null)
             {
                 transid = "00001";
             }
             else
             {
                 transid = (Convert.ToInt32(lasttransID.TransactionId) + 1).ToString();
             }
             SavingsTransaction st = new SavingsTransaction()
             {
                 TransactionId = Int32.Parse(transid), AccountId = AccountID, TransactionDate = DateTime.Now, TransactionType = "SB", Amount = s.Amount
             };
             (from p in ob.SavingsAccounts
              where p.AccountId == AccountID
              select p).ToList().ForEach(x => x.Balance = x.Balance + s.Amount);
             ob.SavingsTransactions.Add(st);
             return(ob.SaveChanges());
         }
     }
     catch (Exception e)
     {
         return(0);
     }
 }