public ActionResult Create(TransaksiPinjamanModel pinjam) { if (Session["id"] == null) { return(RedirectToAction("Index", "Login")); } using (SqlConnection sqlcon = new SqlConnection(connectionString)) { DataTable dtbSimpan = new DataTable(); sqlcon.Open(); KoperasiEntities2 db = new KoperasiEntities2(); List <anggota> list = db.anggotas.ToList(); List <pinjaman> list1 = db.pinjamen.ToList(); ViewBag.anggotaList = new SelectList(list, "no_anggota", "nama_ang"); ViewBag.pinjamanList = new SelectList(list1, "kd_pinj", "jns_pinj"); string query = "SELECT bunga FROM pinjaman where kd_pinj = @kd_pinj"; SqlDataAdapter sqlCmd = new SqlDataAdapter(query, sqlcon); sqlCmd.SelectCommand.Parameters.AddWithValue("@kd_pinj", pinjam.kd_pinj); sqlCmd.Fill(dtbSimpan); trans_pinjaman tpinjam = new trans_pinjaman(); Peminjaman objpinjam = new Peminjaman(); var bunga = Convert.ToDouble(dtbSimpan.Rows[0][0].ToString()); var jumlah = pinjam.jlh; var bungaTot = objpinjam.totalPeminjaman(bunga, jumlah); var total = bungaTot + jumlah; var angsuran = total / pinjam.lama; tpinjam.no_ang = pinjam.no_ang; tpinjam.jlh = pinjam.jlh; tpinjam.keterangan = pinjam.keterangan; tpinjam.lama = pinjam.lama; tpinjam.bunga = Convert.ToDouble(dtbSimpan.Rows[0][0].ToString()); tpinjam.status = "Belum Lunas"; tpinjam.kd_pinj = pinjam.kd_pinj; tpinjam.tglpinj = pinjam.tglpinj; tpinjam.total = total; tpinjam.angsuran = angsuran; db.trans_pinjaman.Add(tpinjam); db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Create(TransaksiSimpananModel simpan) { if (Session["id"] == null) { return(RedirectToAction("Index", "Login")); } using (SqlConnection sqlcon = new SqlConnection(connectionString)) { DataTable dtbSimpan = new DataTable(); sqlcon.Open(); KoperasiEntities2 db = new KoperasiEntities2(); AnggotaModel anggota = new AnggotaModel(); List <anggota> list = db.anggotas.ToList(); List <simpanan> list1 = db.simpanans.ToList(); ViewBag.anggotaList = new SelectList(list, "no_anggota", "nama_ang"); ViewBag.anggotaList1 = new SelectList(list, "no_simp", "nama_ang"); ViewBag.simpananList = new SelectList(list1, "kd_simp", "jns_simp"); string query = "SELECT no_simp FROM anggota where no_anggota = @no_anggota"; SqlDataAdapter sqlCmd = new SqlDataAdapter(query, sqlcon); sqlCmd.SelectCommand.Parameters.AddWithValue("@no_anggota", simpan.no_ang); sqlCmd.Fill(dtbSimpan); trans_simpanan tsimpan = new trans_simpanan(); tsimpan.no_ang = simpan.no_ang; tsimpan.tglsimpan = simpan.tglsimpan; tsimpan.jenis = simpan.jenis; tsimpan.saldo = simpan.saldo; tsimpan.no_simpan = dtbSimpan.Rows[0][0].ToString(); db.trans_simpanan.Add(tsimpan); db.SaveChanges(); } return(RedirectToAction("Index")); }