public ActionResult Create(FormCollection collection) { if (Session["User"] == null) { return(RedirectToAction("Login", "Pages")); } try { // Let's create a new borrower and fill it with form's data BL.Borrower borrower = new BL.Borrower(); borrower.FirstName = collection["FirstName"]; borrower.LastName = collection["LastName"]; borrower.PersonId = collection["PersonId"]; borrower.Address = collection["Address"]; borrower.Telno = collection["Telno"]; borrower.CategoryId = Convert.ToInt32(collection["CategoryId"]); borrower.Username = collection["Username"]; borrower.Password = Settings.SecureString(collection["Password"]); borrower.create(); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(string PersonId, FormCollection collection) { if (Session["User"] == null) { return(RedirectToAction("Login", "Pages")); } try { // Let's create a new borrower and fill it with form's data BL.Borrower borrower = BL.Borrower.getByPersonId(PersonId); borrower.FirstName = collection["FirstName"]; borrower.LastName = collection["LastName"]; borrower.Address = collection["Address"]; borrower.Telno = collection["Telno"]; borrower.CategoryId = Convert.ToInt32(collection["CategoryId"]); borrower.Username = collection["Username"]; // If the password has been changed, let's update it if (collection["Password"] != "") { borrower.Password = Settings.SecureString(collection["Password"]); } // Let's edit the borrower borrower.edit(); borrower.Password = ""; return(RedirectToAction("Index")); } catch { return(View()); } }
public static Borrower getByPersonId(string id) { Borrower newBorrower = null; SqlConnection con = new SqlConnection(Settings.ConnectionString); SqlCommand cmd = new SqlCommand("SELECT * FROM BORROWER WHERE PersonId=@PersonId", con); SqlParameter paramPersonId = new SqlParameter("PersonId", SqlDbType.VarChar); paramPersonId.Value = id; cmd.Parameters.Add(paramPersonId); try { con.Open(); SqlDataReader dar = cmd.ExecuteReader(); if (dar.Read()) { newBorrower = new Borrower(); newBorrower.PersonId = dar["PersonId"] as string; newBorrower.FirstName = dar["FirstName"] as string; newBorrower.LastName = dar["LastName"] as string; newBorrower.Address = dar["Address"] as string; newBorrower.Telno = dar["Telno"] as string; newBorrower.CategoryId = Convert.ToInt32(dar["CategoryId"]); newBorrower.Username = dar["Username"] as string; newBorrower.Password = dar["Password"] as string; } } catch (Exception er) { throw er; } finally { con.Close(); } return(newBorrower); }