/// <summary> /// Pat Banks /// Created: 2015/02/15 /// /// Method takes values for a new employee from the form and passes values /// into the AddNewEmployee method of the EmployeeManager class /// </summary> /// <exception cref="Exception"> /// Exception is thrown if database is not available or /// new employee cannot be created in the database for any reason /// </exception> /// <remarks> /// Miguel Santana /// Updated: 2015/02/22 /// Cast Level to RoleData /// /// Tony Noel /// Updated: 2015/04/13 /// Updated to comply with the ResultsEdit class of error codes. /// </remarks> private async void EmployeeAdd() { if (!Validate()) { return; } try { Debug.Assert(ChkActiveEmployee.IsChecked != null, "ChkActiveEmployee.IsChecked != null"); ResultsEdit result = _employeeManager.AddNewEmployee( new Employee( TxtFirstName.Text, TxtLastName.Text, TxtPassword.Password, (int)CboUserLevel.SelectedItem, ChkActiveEmployee.IsChecked.Value ) ); if (result == ResultsEdit.Success) { await ShowMessage("Employee added successfully"); //closes window after successful add DialogResult = true; Close(); } } catch (Exception ax) { ShowErrorMessage(ax); } }
public ActionResult Create(Employee employee) { bool addedFlag = employeeManager.AddNewEmployee(employee); if (addedFlag) { return(RedirectToAction("Index")); } else { return(View(employee)); } }
public ActionResult CreateEmployee(EmployeeViewModel model) { try { if (!model.LastName.IsValidLastName()) { return(RedirectToAction("Error", "Home", new { errorMessage = model.LastName + "Is not a valid Last Name (100 characters max)" })); } if (!model.LastName.IsValidFirstName()) { return(RedirectToAction("Error", "Home", new { errorMessage = model.FirstName + "Is not a valid Last Name (50 characters max)" })); } var newEmployee = new EmployeeViewModel() { Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PhoneNumber = model.PhoneNumber, Active = model.Active }; List <string> roles = new List <string>(); foreach (var item in model.Roles) { roles.Add((string)item); } newEmployee.Roles = roles; _employeeManager.AddNewEmployee(newEmployee); return(RedirectToAction("Employees", "Employee")); } catch (Exception ex) { string error = ex.Message + "\n\n" + ex.InnerException.Message; if (ex.InnerException.Message.Contains("duplicate")) { error = "Could Not add employee " + model.FirstName; } return(RedirectToAction("Error", "Home", new { errorMessage = error })); } }
private void btnSave_Click(object sender, EventArgs e) { //read input //create object Employee emp = new Employee(); //assign values emp.FirstName = txtFN.Text; emp.LastName = txtLN.Text; emp.DOB = DateTime.Parse(txtDOB.Text); emp.Email = txtEmail.Text; emp.Phone = txtPhone.Text; //call method EmployeeManager manager = new EmployeeManager(); manager.AddNewEmployee(emp); ClearUp(); //message to show user MessageBox.Show("New Employee Added"); }
private void createSupEmployee() { //check for empty form fields if (txtFirstName.Text != "" && txtLastName.Text != "" && txtUsername.Text != "" && txtEmailAddress.Text != "") { //capture form data string roleName = listRole.SelectedValue; string departmentName = listDepartment.SelectedValue; string firstName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(txtFirstName.Text); string lastName = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(txtLastName.Text); string username = txtUsername.Text; string password1 = txtPassword.Text; string password2 = txtPassword2.Text; string emailAddress = txtEmailAddress.Text; //verify passwords match if (password1.Equals(password2)) { //check to make sure password meets min reqs if (_myEmployeeManager.isValidPassword(password1) == true) { //convert password string to md5 string pwdHash = _myEmployeeManager.GeneratePasswordHash(password1); try { try { //check to see if username is currently taken BusinessObjects.Employee checkUsername = _myEmployeeManager.FindEmployee(username); if (checkUsername.Username != null) { System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('Username already exists');", true); } Response.End(); } catch (Exception) { } //create new employee object using form data //since role is supervisor, direct leader is not needed //to eliminate need for managers to create accounts for sups to report to, defaulting supervisor direct leader to 'Hosting' 'Support' BusinessObjects.Employee newEmployee = new BusinessObjects.Employee(); newEmployee.RoleName = roleName; newEmployee.DepartmentName = departmentName; newEmployee.SupervisorFirstName = "Hosting"; newEmployee.SupervisorLastName = "Support"; newEmployee.FirstName = firstName; newEmployee.LastName = lastName; newEmployee.Username = username; newEmployee.Password = pwdHash; newEmployee.EmailAddress = emailAddress; try { //add new employee to db _myEmployeeManager.AddNewEmployee(newEmployee); try { //attempt to auto log in new user account Employee loginEmployee = _myEmployeeManager.FindEmployee(username); Session["loggedInUser"] = loginEmployee; //set flag for agentview page to identify a new user was created Session["newUser"] = "******"; } catch (Exception) { } } catch (Exception) { } } catch (Exception) { } System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('User Created Successfully.');", true); Employee checkRedirect = (Employee)Session["loggedInUser"]; if (checkRedirect.RoleName == "Manager") { Response.Redirect("ManagerView.aspx"); } else { Response.Redirect("AgentView.aspx"); } } else { System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('Password must contain at least one uppercase, one lowercase, one number, and one special character.');", true); } } else { System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('Passwords do not match.');", true); } } else { System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('All fields required!');", true); } }
public void addEmp() { ResultsEdit result = myManager.AddNewEmployee(testEmp); }