protected void btnApply_Click(object sender, EventArgs e) { try { if (Session["ID"] == null) { Response.Redirect("/Index.aspx"); } if (txtCaptcha.Text == "") { lblCaptcha.Visible = true; return; } CaptchaControl1.ValidateCaptcha(txtCaptcha.Text); if (!CaptchaControl1.UserValidated) { lblCaptcha.Visible = true; return; } else { lblCaptcha.Visible = !true; } using (var ctx = new finalContext()) { double val = Convert.ToDouble(txtAmt.Text); var ser = ctx.Services.Find(Convert.ToInt32(Session["Service"])); if (val > ser.MaxValue || val < ser.MinValue) { lblError.Text = "Invalid Loan Amount"; lblError.Visible = true; return; } val = Convert.ToDouble(txtTerm.Text); if (val > ser.MaxTerm || val < ser.MinTerm) { lblError.Text = "Invalid Desired Term"; lblError.Visible = true; return; } int n = Convert.ToInt32(Session["ID"]); var c = ctx.TemporaryLoanApplications.Where(x => x.ClientID == n).Count(); if (c > 0) { using (var ictx = new finalContext()) { int num = Convert.ToInt32(Session["ID"]); var ln = ictx.TemporaryLoanApplications.Where(x => x.ClientID == num).First(); ln.Mode = cmbMode.Text; ln.AmountApplied = Convert.ToDouble(txtAmt.Text); ln.Term = Convert.ToInt32(txtTerm.Text); ln.ServiceID = ser.ServiceID; ictx.Entry(ln).State = System.Data.EntityState.Modified; ictx.SaveChanges(); Session["tempLoan"] = ln.TemporaryLoanApplicationID.ToString(); Response.Redirect("/ApplicationSuccess.aspx"); //Response.Redirect("/MyAccount_Loans.aspx"); return; } } TemporaryLoanApplication lon = new TemporaryLoanApplication { AmountApplied = Convert.ToDouble(txtAmt.Text), ClientID = Convert.ToInt32(Session["ID"]), DateApplied = DateTime.Now.Date, ExpirationDate = DateTime.Now.Date.AddMonths(1), Mode = cmbMode.Text, ServiceID = Convert.ToInt32(Session["Service"]), Term = Convert.ToInt32(txtTerm.Text) }; ctx.TemporaryLoanApplications.Add(lon); ctx.SaveChanges(); Session["tempLoan"] = lon.TemporaryLoanApplicationID.ToString(); string folderName = @"F:\Loan Files\Applications Online"; string pathString = System.IO.Path.Combine(folderName, "Application " + Session["tempLoan"]); if (!Directory.Exists(pathString)) { System.IO.Directory.CreateDirectory(pathString); } else { Directory.Delete(pathString, true); System.IO.Directory.CreateDirectory(pathString); } Response.Redirect("/ApplicationSuccess.aspx"); } } catch (Exception) { //Response.Redirect("/Index.aspx"); } }