예제 #1
0
 public static void AddPayment(Credit credit, double amount)
 {
     BankContext bank = new BankContext();
     Payment payment = new Payment();
     payment.CreditId = credit.Id;
     payment.Amount = amount;
     payment.PayDate = DateTime.UtcNow;
     bank.Payments.Add(payment);
     bank.SaveChanges();
 }
예제 #2
0
 public static List<Credit> GetCreditsByCurrency(Currency currency)
 {
     List<Credit> credits = new List<Credit>();
     BankContext bank = new BankContext();
     foreach (var credit in bank.Credits.Where(x => x.Currency == currency))
     {
         credits.Add(credit);
     }
     return credits;
 }
예제 #3
0
 /// <summary>
 /// RemoveAccount возвращает true, если account был удален, false в противном случае
 /// </summary>
 /// <param name="account"></param>
 /// <returns></returns>
 public static bool RemoveAccount(Account account)
 {
     BankContext bank = new BankContext();
     if(bank.Accounts.Find(account.Id) != null)
     {
         bank.Accounts.Remove(account);
         bank.SaveChanges();
         return true;
     }
     return false;
 }
예제 #4
0
 public static List<Payment> GetPaymentsByCredit(string creditId)
 {
     List<Payment> payments = new List<Payment>();
     BankContext bank = new BankContext();
     foreach (var payment in bank.Payments)
     {
         if (payment.CreditId.Equals(creditId))
             payments.Add(payment);
     }
     return payments;
 }
예제 #5
0
 public static List<Account> GetAccounts(User client)
 {
     BankContext bank = new BankContext();
     List<Account> accounts = new List<Account>();
     foreach (var item in bank.Accounts.ToList())
     {
         if (item.ClientId.ToString().Equals(client.Id))
         {
             accounts.Add(item);
         }
     }
     return accounts;
 }
예제 #6
0
        public static void CreateAccount(User client, Currency currency)
        {
            BankContext bank = new BankContext();
            Account account = new Account();

            account.ClientId = client.Id;
            account.OpeningDate = DateTime.UtcNow;
            account.Currency = currency;
            account.Amount = 0;

            bank.Accounts.Add(account);
            bank.SaveChanges();
        }
예제 #7
0
 public static bool EditCurrencyInAccount(Account account, Currency newCurrency)
 {
     BankContext bank = new BankContext();
     var accountInDb = bank.Accounts.SingleOrDefault(a => a.Id == account.Id);
     if (accountInDb != null)
     {
         Money money = new Money(accountInDb.Currency,accountInDb.Amount);
         money.Exchange(newCurrency);
         accountInDb.Currency = newCurrency;
         accountInDb.Amount = money.Amount;
         bank.SaveChanges();
         return true;
     }
     return false;
 }
예제 #8
0
 public static void AddCredit(Account account, Currency currency, double amount, double rate, PaymentType payment, int term)
 {
     BankContext bank = new BankContext();
     bank.Credits.Add(new Credit()
     {
         AccountId = account.Id,
         Currency = currency,
         Amount = amount,
         Rate = rate,
         PaymentType = payment,
         Months = term,
         LoanDate = DateTime.UtcNow,
         Status = CreditStatus.Active
     });
     bank.SaveChanges();
 }
예제 #9
0
        public static bool ArchiveCredit(Credit credit)
        {
            BankContext bank = new BankContext();
            if (bank.Credits.Contains(credit))
            {
                try
                {
                    if (Archive(credit) == true)
                        return true;
                    else
                        return false;
                }
                catch (Exception)
                {

                }
            }
            return false;
        }
예제 #10
0
 public static List<Credit> GetCreditsByDate(DateTime date)
 {
     List<Credit> credits = new List<Credit>();
     BankContext bank = new BankContext();
     foreach (var credit in bank.Credits.Where(x => x.LoanDate == date))
     {
         credits.Add(credit);
     }
     return credits;
 }
예제 #11
0
 public static List<Credit> GetCreditsWithProcentAmountGreaterThan(double amountBounder)
 {
     var credits = new List<Credit>();
     var bank = new BankContext();
     foreach (var credit in bank.Credits.Where(x => PaymentCalculator.CalculateMonthlyProcentAmount(x) >= amountBounder))
     {
         credits.Add(credit);
     }
     return credits;
 }
예제 #12
0
 public static List<Credit> GetCreditsLessThanAmount(double amount)
 {
     var credits = new List<Credit>();
     var bank = new BankContext();
     foreach (var credit in bank.Credits.Where(x => x.Amount <= amount))
     {
         credits.Add(credit);
     }
     return credits;
 }
예제 #13
0
 public static List<Credit> GetCreditsGreaterThanAmount(double amount)
 {
     List<Credit> credits = new List<Credit>();
     BankContext bank = new BankContext();
     foreach (var credit in bank.Credits.Where(x => x.Amount >= amount))
     {
         credits.Add(credit);
     }
     return credits;
 }
예제 #14
-1
        public static bool EditCredit(Credit creditToEdit, double? amount, Currency? currency, double? rate, int? months)
        {
            BankContext bank = new BankContext();
            if (!bank.Credits.Contains(creditToEdit))
                return false;
            else
            {
                try
                {
                    if (amount != null)
                        creditToEdit.Amount = (double)amount;
                    if (currency != null)
                        creditToEdit.Currency = (Currency)currency;
                    if (months != null)
                        creditToEdit.Months= (int)months;
                    if (rate != null)
                        creditToEdit.Rate = (double)rate;
                    bank.SaveChanges();
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }

            }
        }