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