using System; using System.Data; using System.Configuration; using System.Collections; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Web.UI.HtmlControls; using System.Text.RegularExpressions; using ButterfieldGardens.Web; public partial class admin_index : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (Session["USERID"] == null) { Response.Redirect("/admin/"); } Navigation objNav = new Navigation(); header.InnerHtml = objNav.GetAdminHeader(); adminNav.InnerHtml = objNav.GetAdminSubNavMenu("users"); footer.InnerHtml = objNav.GetFooter(false, false); } protected void SaveUser(object sender, EventArgs e) { try { ValidateUserInput(); AddUser(); Response.Redirect("/admin/manage-users.aspx"); } catch (Exception ex) { DisplayErrorMessage(ex); } } public void ValidateUserInput() { Boolean isValid = true; if (txtFirstName.Text.Equals("")) { isValid = false; } if (txtLastName.Text.Equals("")) { isValid = false; } if (txtEmail.Text.Equals("")) { isValid = false; } else { String strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" + @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" + @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$"; Regex re = new Regex(strRegex); if (!re.IsMatch(txtEmail.Text)) { isValid = false; } } if (txtPassword.Text.Equals("")) { isValid = false; } if (ddActive.SelectedValue.Equals("")) { isValid = false; } if (isValid.Equals(false)) { throw (new Exception("All fields are required for this form. Please try again.")); } } public void AddUser() { cUserDAO objUserDAO = new cUserDAO(); cUser objUser = new cUser(); objUser.FirstName = txtFirstName.Text; objUser.LastName = txtLastName.Text; objUser.EmailAddress = txtEmail.Text; objUser.IsActive = Convert.ToBoolean(ddActive.SelectedValue); objUserDAO.AddUser(objUser, txtPassword.Text); objUser.Dispose(); objUserDAO.Dispose(); } public void DisplayErrorMessage(Exception exError) { Literal lit = new Literal(); lit.Text = exError.Message; lblNotify.Controls.Add(lit); lblNotify.CssClass = "error"; lblNotify.Visible = true; } }