protected void btn_submit_Click(object sender, EventArgs e) { try { using (var db = new THFinanceEntities()) { tbl_PaymentType tbl = new tbl_PaymentType(); var q = (from s in db.tbl_PaymentType select s).ToList(); tbl.paymentBorrowerId = Convert.ToInt32(ddl_paymentborrwer.SelectedValue); tbl.PaymentDate = Convert.ToDateTime(txt_startdate.Value); tbl.PaymentType = txt_PaymentType.Value; tbl.PaymentAmount = Convert.ToInt32(txt_PaymentAmount.Text); tbl.givenamount = txt_givenAmount.Text; tbl.paymentmethod = Convert.ToInt32(ddl_chitti.SelectedValue); tbl.monthlyInterest = txt_monthlypayment.Text; if (q.Count == 0) { db.tbl_PaymentType.Add(tbl); db.SaveChanges(); Response.Write("<script>alert('Sucessfully saved')</script>"); loadgrid(); clearfields(); return; } else { for (int i = 0; i < q.Count; i++) { var present = tbl.paymentBorrowerId; var prev = q[i].paymentBorrowerId; if (present == prev) { Response.Write("<script>alert('Borrower already exist')</script>"); return; } } } db.tbl_PaymentType.Add(tbl); db.SaveChanges(); Response.Write("<script>alert('Sucessfully saved')</script>"); clearfields(); } } catch (Exception ex) { throw ex; } }
protected void btn_update_Click(object sender, EventArgs e) { using (var context = new THFinanceEntities()) { int id = Convert.ToInt32(lbl_id.Text); tbl_PaymentType tbl = (from s in context.tbl_PaymentType where s.paymentId.Equals(id) select s).Single(); tbl.paymentBorrowerId = Convert.ToInt32(ddl_paymentborrwer.SelectedValue); tbl.PaymentDate = Convert.ToDateTime(txt_startdate.Value); tbl.PaymentType = txt_PaymentType.Value; tbl.givenamount = txt_givenAmount.Text; tbl.PaymentAmount = Convert.ToInt32(txt_PaymentAmount.Text); context.SaveChanges(); Response.Write("<script>alert('Sucessfully saved')</script>"); loadgrid(); clearfields(); } }