public ActionResult MakePayment(LoanPaymentViewModel model, int id)
        {
            if (ModelState.IsValid)
            {
                Loan loan = db.Loans.Find(id);

                var Amount = model.PaymentMade;

                var nextPaymentDate = loan.PaymentDate;

                if (loan.PaymentAmount == null)
                {
                    loan.PaymentAmount = (decimal)0;
                }

                loan.PaymentAmount += Amount;
                loan.PaymentDate    = generatePayment(nextPaymentDate);

                db.Entry(loan).State = EntityState.Modified;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
示例#2
0
        public static IList <LoanPaymentViewModel> MapToViewModelsList(this IList <LoanPayment> loanPayments)
        {
            List <LoanPaymentViewModel> viewModels = new List <LoanPaymentViewModel>();

            if (loanPayments != null && loanPayments.Count > 0)
            {
                foreach (LoanPayment c in loanPayments)
                {
                    LoanPaymentViewModel viewModel = c.MapToViewModel();
                    if (viewModel != null)
                    {
                        viewModels.Add(viewModel);
                    }
                }
            }

            return(viewModels);
        }
示例#3
0
        public static LoanPaymentViewModel MapToViewModel(this LoanPayment LoanPayment)
        {
            LoanPaymentViewModel viewModel = null;

            if (LoanPayment != null)
            {
                viewModel = new LoanPaymentViewModel
                {
                    Amount          = LoanPayment.Amount,
                    LoanPaymentId   = LoanPayment.Id,
                    Comments        = LoanPayment.Comments,
                    Description     = LoanPayment.Description,
                    MonthlyBudgetId = LoanPayment.MonthlyBudgetId,
                    PaymentDate     = LoanPayment.PaymentDate,
                    LoanId          = LoanPayment.LoanId,
                    CreationDate    = LoanPayment.CreationDate,
                    LastModified    = LoanPayment.LastModifited
                };
            }

            return(viewModel);
        }
示例#4
0
        public static LoanPayment MapToModel(this LoanPaymentViewModel viewModel)
        {
            LoanPayment loanPayment = null;

            if (viewModel != null)
            {
                loanPayment = new LoanPayment
                {
                    Amount          = viewModel.Amount,
                    Comments        = viewModel.Comments,
                    Description     = viewModel.Description,
                    Id              = viewModel.LoanPaymentId,
                    MonthlyBudgetId = viewModel.MonthlyBudgetId,
                    PaymentDate     = viewModel.PaymentDate,
                    LoanId          = viewModel.LoanId,
                    CreationDate    = viewModel.CreationDate,
                    LastModifited   = viewModel.LastModified
                };
            }

            return(loanPayment);
        }