protected void BtnSubmit_OnClick(object sender, EventArgs e) { //Declaring variables needed LblStatus.Visible = false; FlexiLearn___ClassLibrary.User user; var education = (Education)Enum.Parse(typeof(Education), LstEducation.SelectedItem.ToString()); //Checking to see if all web controls are valid if (Page.IsValid) { //Checking to see if number is empty because the User object differs based on it if (TxtNumber.Text != "") { LblStatus.Visible = true; try { //Creating the user and inserting the user to database user = new FlexiLearn___ClassLibrary.User( TxtUserName.Text, TxtEmail.Text, education, DateTime.Parse(TxtDate.Text), TxtPassword.Text, TxtNumber.Text); _userDao.AddRecord(user, DateTime.Today); //Displaying success message LblStatus.Text = "User " + user.Name + " has been created!"; } catch (Exception ex) { //Displaying the exception message LblStatus.Text = ex.Message; } } else { LblStatus.Visible = true; try { //Creating the user and inserting the user to database user = new FlexiLearn___ClassLibrary.User( TxtUserName.Text, TxtEmail.Text, education, DateTime.Parse(TxtDate.Text), TxtPassword.Text); _userDao.AddRecord(user, DateTime.Today); //Displaying success message LblStatus.Text = "User " + user.Name + " has been created!"; } catch (Exception ex) { //Displaying the exception message LblStatus.Text = ex.Message; } } } }
protected void BtnRegister_OnClick(object sender, EventArgs e) { //Declaring the dao that is needed to access Users var userDao = new UserDao(); //Adding the user record to the users table within the database (int, int)result = userDao.AddRecord(TxtUser.Text, TxtPassword.Text); //If successful, redirect newly registered user to the login page if (result.Item2 > 0) { Response.Redirect("/Login.aspx"); } }