protected void btnCreate_Click(object sender, EventArgs e) { try { bool mailFlag = false; if (!(string.IsNullOrEmpty(txtName.Text) && (string.IsNullOrEmpty(txtMail.Text)))) { if (Regex.IsMatch(txtMail.Text.Trim(), @"^(?("")("".+?""@)|(([0-9a-zA-Z]((\.(?!\.))|[-!#\$%&'\*\+/=\?\^`\{\}\|~\w])*)(?<=[0-9a-zA-Z])@))(?(\[)(\[(\d{1,3}\.){3}\d{1,3}\])|(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]\.)+[a-zA-Z]{2,6}))$")) { var duplicateEmail = Global.Core.Users.GetSingle("Mail", txtMail.Text.Trim()); if (duplicateEmail != null) { Response.Redirect("CreateUser.aspx" + "?msg=3", false); } else { //var single = Global.Core.Users.GetSingle("Name", txtName.Text.Trim()); //if (single != null) //{ // Response.Redirect("CreateUser.aspx" + "?msg=3", false); //} //else //{ //password = Membership.GeneratePassword(8, 2); password = GeneratePassword(); // Adding User Details to the Table User user = new User(Global.Core.Users) { Name = txtName.Text.Trim(), FirstName = txtFirstName.Text.Trim(), LastName = txtLastName.Text.Trim(), Mail = txtMail.Text.Trim(), Password = Global.Core.Users.GetMD5Hash(password), //Global.Core.Users.GetMD5Hash(txtUserPassword.Text.Trim()), Phone = txtPhone.Text, Language = Global.Language.ToString(), Browser = Request.Browser.Browser }; user.Insert(); var userRole = new UserRole(Global.Core.UserRoles) { IdUser = user.Id, IdRole = Guid.Parse(ddlRole.SelectedValue.Trim()) }; userRole.Insert(); AssignWorkgroups(user.Id); mailFlag = SendMail(); if (mailFlag) { SendConfirmMail(); } UserValidation userValidation = new UserValidation(Path.Combine( Request.PhysicalApplicationPath, "App_Data", "UserValidation", Global.Core.ClientName + ".xml" )); Dictionary <string, List <object[]> > values = Global.Core.UserValidationFieldValues.ExecuteReaderDict <string>( "SELECT Field, Id FROM [UserValidationFieldValues] WHERE IdUser={0}", new object[] { user.Id } ); foreach (string field in userValidation.Fields.Keys) { if (Request.Params["ctl00$cphContent$ctlUserValidationField" + field] == null) { continue; } if (values.ContainsKey(field)) { Global.Core.UserValidationFieldValues.SetValue( "Id=" + values[field][0][1], "Value", Request.Params["ctl00$cphContent$ctlUserValidationField" + field] ); } else { UserValidationFieldValue value = new UserValidationFieldValue(Global.Core.UserValidationFieldValues); value.IdUser = user.Id; value.Field = field; value.Value = Request.Params["ctl00$cphContent$ctlUserValidationField" + field]; value.Insert(); } } ClearFeilds(); if (chkMultiple.Checked) { Response.Redirect("CreateUser.aspx" + "?msg=1", false); } else { Response.Redirect("UsersHome.aspx" + "?msg=1", false); } //} } } else { Response.Redirect("CreateUser.aspx" + "?msg=4", false); } } } catch (Exception ex) { HttpContext.Current.Session["Error"] = ex.Message.Trim(); Response.Redirect("CreateUser.aspx" + "?msg=2", false); } }
protected void btnAcceptChanges_Click(object sender, EventArgs e) { if (HttpContext.Current.Session["Muser"] != null) { try { var oId = HttpContext.Current.Session["thisUser"]; AssignWorkgroups(Guid.Parse(oId.ToString())); if (oId != null) { if (ddlRole.SelectedValue.Trim() != "select" && txtMail.Text != "") { UserValidation userValidation = new UserValidation(Path.Combine( Request.PhysicalApplicationPath, "App_Data", "UserValidation", Global.Core.ClientName + ".xml" )); Dictionary <string, List <object[]> > values = Global.Core.UserValidationFieldValues.ExecuteReaderDict <string>( "SELECT Field, Id FROM [UserValidationFieldValues] WHERE IdUser={0}", new object[] { Guid.Parse(oId.ToString()) } ); foreach (string field in userValidation.Fields.Keys) { if (Request.Params["ctl00$cphContent$ctlUserValidationField" + field] == null) { continue; } if (values.ContainsKey(field)) { Global.Core.UserValidationFieldValues.SetValue( "Id=" + values[field][0][1], "Value", Request.Params["ctl00$cphContent$ctlUserValidationField" + field] ); } else { UserValidationFieldValue value = new UserValidationFieldValue(Global.Core.UserValidationFieldValues); value.IdUser = Guid.Parse(oId.ToString()); value.Field = field; value.Value = Request.Params["ctl00$cphContent$ctlUserValidationField" + field]; value.Insert(); } } var oldValues = Global.Core.Users.GetSingle(Guid.Parse(oId.ToString())); var roleValue = ""; if (oldValues.Role != null) { roleValue = oldValues.Role.Name.Trim(); } if ((oldValues.Name == txtName.Text.Trim()) && (oldValues.FirstName == txtFirstName.Text.Trim()) && (oldValues.LastName == txtLastName.Text.Trim()) && (oldValues.Mail == txtMail.Text.Trim()) && (oldValues.Phone == txtPhone.Text.Trim()) && (roleValue == ddlRole.SelectedItem.Text)) { //Response.Redirect("ManageUsers.aspx?msg=5", false); Response.Redirect("ManageUsers.aspx", false); } else { var single = Global.Core.Users.GetSingle(Guid.Parse(oId.ToString())); if (single != null) { // Adding User Details to the Table single.Name = txtName.Text.Trim(); single.FirstName = txtFirstName.Text.Trim(); single.LastName = txtLastName.Text.Trim(); single.Mail = txtMail.Text.Trim(); single.Phone = txtPhone.Text.Trim(); single.Browser = Request.Browser.Browser; single.Save(); var userRole = Global.Core.UserRoles.GetSingle("IdUser", HttpContext.Current.Session["Muser"].ToString()); if (userRole != null) { userRole.IdUser = single.Id; userRole.IdRole = Guid.Parse(ddlRole.SelectedValue.Trim()); userRole.Save(); } else { userRole = new UserRole(Global.Core.UserRoles) { IdUser = single.Id, IdRole = Guid.Parse(ddlRole.SelectedValue.Trim()) }; userRole.Insert(); } //SendMail(); //// configuration values from the web.config file. //MailConfiguration mailConfiguration = new MailConfiguration(true); //// Create a new mail by the mail configuration. //Mail mail = new Mail(mailConfiguration, Global.Core.ClientName) //{ // TemplatePath = Path.Combine( // Request.PhysicalApplicationPath, // "App_Data", // "MailTemplates", // Global.Language.ToString(), // "ModifyOwnerTemplate.html" // ), // Subject = "mail from Link online team" //}; //// Set the full path to the mail's template file. //// Add the placeholder value for the user's first name. //mail.Placeholders.Add("imagepath", "http://" + Request.Url.ToString().Split('/')[2] + "/Images/Logos/link.png"); //mail.Placeholders.Add("FirstName", txtFirstName.Text.Trim()); //mail.Placeholders.Add("LastName", txtLastName.Text.Trim()); //if ((oldValues.FirstName != txtFirstName.Text.Trim()) && (oldValues.LastName != txtLastName.Text.Trim())) //{ // mail.Placeholders.Add("Message", "your first name and last name has been changed from"); // mail.Placeholders.Add("OldValue", oldValues.FirstName + " , " + oldValues.LastName); // mail.Placeholders.Add("NewValue", txtFirstName.Text.Trim() + " , " + txtLastName.Text.Trim() + " respectively"); //} //else if ((oldValues.Mail != txtMail.Text.Trim()) && (oldValues.Phone != txtPhone.Text.Trim())) //{ // mail.Placeholders.Add("Message", "your phone number and email has been changed from"); // mail.Placeholders.Add("OldValue", oldValues.Phone + " , " + oldValues.Mail); // mail.Placeholders.Add("NewValue", txtPhone.Text.Trim() + " , " + txtMail.Text.Trim() + " respectively"); //} //else if (oldValues.Name != txtName.Text.Trim()) //{ // mail.Placeholders.Add("Message", "your user name has been changed from"); // mail.Placeholders.Add("OldValue", oldValues.Name); // mail.Placeholders.Add("NewValue", txtName.Text.Trim()); //} //else if (oldValues.FirstName != txtFirstName.Text.Trim()) //{ // mail.Placeholders.Add("Message", "your first name has been changed from"); // mail.Placeholders.Add("OldValue", oldValues.FirstName); // mail.Placeholders.Add("NewValue", txtFirstName.Text.Trim()); //} //else if (oldValues.LastName != txtLastName.Text.Trim()) //{ // mail.Placeholders.Add("Message", "your last name has been changed from"); // mail.Placeholders.Add("OldValue", oldValues.LastName); // mail.Placeholders.Add("NewValue", txtLastName.Text.Trim()); //} //else if (oldValues.Mail != txtMail.Text.Trim()) //{ // mail.Placeholders.Add("Message", "your email has been changed from"); // mail.Placeholders.Add("OldValue", oldValues.Mail); // mail.Placeholders.Add("NewValue", txtMail.Text.Trim()); //} //else if (oldValues.Phone != txtPhone.Text.Trim()) //{ // mail.Placeholders.Add("Message", "your phone number has been changed from"); // mail.Placeholders.Add("OldValue", oldValues.Phone); // mail.Placeholders.Add("NewValue", txtPhone.Text.Trim()); //} //else if (roleValue != ddlRole.SelectedItem.Text.Trim()) //{ // mail.Placeholders.Add("Message", "your role has been changed from"); // mail.Placeholders.Add("OldValue", roleValue); // mail.Placeholders.Add("NewValue", ddlRole.SelectedItem.Text.Trim()); //} //mail.Placeholders.Add("clientsubdomain", "http://" + Request.Url.ToString().Split('/')[2].ToString()); //// Send the mail. //mail.Send(txtMail.Text.Trim()); Response.Redirect("ManageUsers.aspx?msg=1", false); } } } else { HttpContext.Current.Session["Error"] = "select the user role"; Response.Redirect("ManageUsers.aspx?msg=2", false); } } else { Response.Redirect("Default.aspx", false); } } catch (Exception ex) { HttpContext.Current.Session["Error"] = ex.Message; Response.Redirect("ManageUsers.aspx?msg=2", false); } } else { Response.Redirect("/Pages/Login.aspx"); } }