Ejemplo n.º 1
0
        public IActionResult TakeRepayLoan()
        {
            // Member list
            var viewModel = new LoanTransactionViewModel();

            viewModel.DaftarAnggota = _memberService.GetMembers();

            return(View(viewModel));
        }
Ejemplo n.º 2
0
        public IActionResult EditLoan(LoanTransactionViewModel loanTransaction)
        {
            var loan = _loanService.GetById(loanTransaction.NomorPinjaman);

            if (loan == null)
            {
                ModelState.AddModelError("NomorPinjaman", "Nomor pinjaman tidak ada");
                return(View("EditLoan"));
            }

            return(RedirectToAction("Edit", new { id = loanTransaction.NomorPinjaman }));
        }
Ejemplo n.º 3
0
        public IActionResult Edit([Bind("NomorAnggota, NomorPinjaman, PersentaseBunga, JumlahPinjaman, LamaPinjaman")] LoanTransactionViewModel loanTransaction)
        {
            if (!ModelState.IsValid)
            {
                return(View(loanTransaction));
            }

            var updatedLoanTransaction = ViewModelMapper.MapViewModelToModel <LoanTransactionViewModel, LoanTransactionModel>(loanTransaction, new LoanTransactionModel());

            _loanService.Update(updatedLoanTransaction);

            return(RedirectToAction("EditLoan"));
        }
Ejemplo n.º 4
0
        public IActionResult TakeRepayLoan(LoanTransactionViewModel transactionVM)
        {
            dynamic transaction = null;

            if (transactionVM.NomorAnggota <= 0)
            {
                return(View(transactionVM));
            }

            if (transactionVM.JenisTransaksi == LoanTransactionType.PinjamanUang)
            {
                if (transactionVM.PersentaseBunga < 0 || transactionVM.JumlahPinjaman <= 0)
                {
                    return(View(transactionVM));
                }
                transaction = ViewModelMapper.MapViewModelToModel(transactionVM, new LoanTransactionModel());
            }
            else
            {
                if (transactionVM.JumlahPinjamanPokok <= 0 || transactionVM.JumlahBungaPinjaman <= 0 || transactionVM.NomorPinjaman <= 0)
                {
                    return(View(transactionVM));
                }

                // Validate the loan belongs to the member
                var loanExists = _loanService.GetById(transactionVM.NomorPinjaman);
                if (loanExists == null)
                {
                    ModelState.AddModelError("", "Nomor pinjaman tidak ada untuk nomor anggota ini.");

                    // Member list
                    transactionVM.DaftarAnggota = _memberService.GetMembers();
                    return(View(transactionVM));
                    //return RedirectToAction("TakeRepayLoan", transactionVM);
                }

                transaction = ViewModelMapper.MapViewModelToModel(transactionVM, new LoanRepaymentTransactionModel());
            }

            if (transactionVM.JenisTransaksi == LoanTransactionType.PinjamanUang)
            {
                _loanService.Save(transaction);
            }
            else
            {
                _loanRepaymentService.Save(transaction);
            }

            return(RedirectToAction(nameof(ClearForm), new { ActionName = "TakeRepayLoan" }));
        }