public IActionResult BuySell(ShareTransactionViewModel transactionVM) { if (transactionVM.NomorAnggota == 0 || transactionVM.NomorHargaSaham == 0) { return(View(transactionVM)); } var transaction = new ShareTransactionModel(); if (ModelState.IsValid) { var memberHolding = _shareService.GetShareholdingByMemberId(transactionVM.NomorAnggota); if (transactionVM.JenisTransaksi == ShareTransactionType.JualSaham) { if (memberHolding < transactionVM.JumlahSaham) { ModelState.AddModelError("JumlahSaham", "Anggota tidak memiliki jumlah saham yang memadai untuk penjualan"); transactionVM.DaftarAnggota = _memberService.GetMembers(); transactionVM.DaftarHargaSaham = _shareService.GetSharePriceList(); return(View(transactionVM)); } } transaction = ViewModelMapper.MapViewModelToModel(transactionVM, transaction); _shareTransactionService.Save(transaction); return(RedirectToAction(nameof(ClearForm), new { ActionName = "BuySell" })); } return(View(transactionVM)); }
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")); }
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" })); }
public IActionResult EditBuyShare(int?id) { if (id == null) { return(NotFound()); } var share = _shareTransactionService.GetById(id); if (share == null) { return(NotFound()); } var shareTransaction = ViewModelMapper.MapViewModelToModel(share, new EditShareTransactionViewModel()); shareTransaction.DaftarAnggota = _memberService.GetMembers(); shareTransaction.DaftarHarga = _shareService.GetSharePriceList(); return(View(shareTransaction)); }
public IActionResult Edit(int?id) { if (id == null) { return(RedirectToAction("EditLoan")); } var loanTransaction = _loanService.GetById(id); if (loanTransaction == null) { ModelState.AddModelError("NomorPinjaman", "Nomor pinjaman tidak ada."); return(RedirectToAction("EditLoan")); } var loan = ViewModelMapper.MapViewModelToModel <LoanTransactionModel, LoanTransactionViewModel>(loanTransaction, new LoanTransactionViewModel()); loan.DaftarAnggota = _memberService.GetMembers(); return(View(loan)); }
public IActionResult EditBuyShare(EditShareTransactionViewModel editShareTransaction) { if (!ModelState.IsValid) { return(View(editShareTransaction)); } if (editShareTransaction.JumlahSaham <= 0) { ModelState.AddModelError("JumlahSaham", "Jumlah saham tidak boleh < 0"); editShareTransaction.DaftarAnggota = _memberService.GetMembers(); editShareTransaction.DaftarHarga = _shareService.GetSharePriceList(); return(View(editShareTransaction)); } var updatedShareTransaction = ViewModelMapper.MapViewModelToModel(editShareTransaction, new ShareTransactionModel()); _shareTransactionService.Update(updatedShareTransaction); return(RedirectToAction("EditBuy")); }