private void Update(Account account) { this.AccountLimit = account.AccountLimit; this.AccountTypeId = account.AccountTypeId; this.Available = account.Available; this.CreditRate = account.CreditRate; this.DebitRate = account.DebitRate; this.Floating = account.Floating; this.FloatingType = account.FloatingType; this.InstitutionId = account.InstitutionId; this.MonthlyFee = account.MonthlyFee; this.Name = account.Name; this.NetAmount = account.NetAmount; this.AccountIdentifier = account.AccountIdentifier; this.Maturity = account.Maturity; this.MonthlyPayment = account.MonthlyPayment; this.isDummy = account.isDummy; if (account.Floating) { RateInformation information = new RateInformation(); this.Spread = information.GetSpread(account); } else { this.Spread = 0; } AccountType type = new AccountType(); if (type.isAmortised(account.AccountTypeId) && account.Maturity != DateTime.MinValue && account.MonthlyPayment != 0) { AccountAmortisation amortisation = new AccountAmortisation(); amortisation.Update(account); } }
public void Create(Account account, PaymentModel payment, AccountAmortisation amortisation) { DateTime end = account.Maturity; DateTime start = DateTime.Now; start = new DateTime(start.Year, start.Month, end.Day); List <MonthlyAmortisation> monthlies = new List <MonthlyAmortisation>(); double amount = account.Available; for (int i = 0; end.Date > start.AddMonths(i).Date; i++) { MonthlyAmortisation monthly = new MonthlyAmortisation { MonthlyAmortisationId = Guid.NewGuid().ToString(), AccountAmortisationId = amortisation.AccountAmortisationId, Date = start.AddMonths(i), Open = amount }; monthly.Interest = amount * (account.CreditRate / 12 / 100); monthly.Payment = payment.CostOfLoan; monthly.Capital = monthly.Payment - monthly.Interest; monthly.Additional = payment.AdditionalLoan; monthly.Close = amount - monthly.Capital - monthly.Additional; monthlies.Add(monthly); amount = monthly.Close; if (amount < 0) { break; } } using (FinPlannerContext _context = new FinPlannerContext()) { _context.AddRange(monthlies); try { _context.SaveChanges(); } catch (Exception e) { ExceptionCatcher catcher = new ExceptionCatcher(); catcher.Catch(e.Message); } } }
public void Update(Account account) { if (isExists(account.Id)) { } else { AccountAmortisation amortisation = new AccountAmortisation() { AccountId = account.Id, AccountAmortisationId = Guid.NewGuid().ToString() }; using (FinPlannerContext _context = new FinPlannerContext()) { _context.Add(amortisation); try { _context.SaveChanges(); } catch (Exception e) { ExceptionCatcher catcher = new ExceptionCatcher(); catcher.Catch(e.Message); } } PaymentModel payment = new PaymentModel(account, amortisation.AccountAmortisationId); using (FinPlannerContext _context = new FinPlannerContext()) { _context.Add(payment); try { _context.SaveChanges(); } catch (Exception e) { ExceptionCatcher catcher = new ExceptionCatcher(); catcher.Catch(e.Message); } } MonthlyAmortisation monthly = new MonthlyAmortisation(); monthly.Create(account, payment, amortisation); } }