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(); }
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; }
/// <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; }
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; }
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; }
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(); }
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; }
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(); }
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; }
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; }
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; }
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; }
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; }
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; } } }