// Deletes a department public ActionResult Delete() { // Null handling if (Session["loggedInState"] == null) { return(Redirect("/403.html")); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { int departmentID = int.Parse(RouteData.Values["id"].ToString()); // Establishes models DepartmentModel departmentModel = new DepartmentModel(); EmployeeModel employeeModel = new EmployeeModel(); // Gets list of all employees var employeeList = employeeModel.GetEmployeesList(); // For each employee within the list foreach (var employee in employeeList) { // If the employee belongs to department if (employee.Dept == departmentID) { // Sets department to none employee.Dept = 0; // Saves employee to database employeeModel.EditEmployee(employee); } } // Deletes the department from the database using the ID departmentModel.DeleteDepartment(departmentID); // TODO: Confirm this is the correct return state // Return to department listing return(Redirect("../department")); } else { // If not logged in return(Redirect("/login.html")); } }
// Deletes a depot public ActionResult Delete() { // Null handling if (Session["loggedInState"] == null) { return(Redirect("/403.html")); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { int depotID = int.Parse(RouteData.Values[""].ToString()); // Establishes models DepotModel depotModel = new DepotModel(); EmployeeModel employeeModel = new EmployeeModel(); // Gets list of all employees var employeeList = employeeModel.GetEmployeesList(); // For each employee in depot foreach (var employee in employeeList) { // If employee belongs to depot if (employee.Depot == depotID) { // Sets the depot to null employee.Depot = 0; // Saves employee to database employeeModel.EditEmployee(employee); } } // Deletes the depot from the database using the ID depotModel.DeleteDepot(depotID); return(Redirect("/..depot")); } else { // If not logged in return(Redirect("/login.html")); } }
// Controller for modification of an employee public ActionResult EditEmployee() { // Null handling if (Session["loggedInState"] == null) { return(Redirect("/403.html")); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Creates an employee placeholder var employee = new Employee(); // Setup employee edit employee.Id = int.Parse(Request.Form["id"]); employee.Firstname = Request.Form["firstname"]; employee.Lastname = Request.Form["lastname"]; employee.DOB = DateTime.Parse(Request.Form["DOB"]); employee.ContactNumber = Request.Form["contactNum"]; employee.Startdate = DateTime.Parse(Request.Form["startDate"]); employee.Dept = int.Parse(Request.Form["depart"]); employee.Depot = int.Parse(Request.Form["depot"]); employee.Role = int.Parse(Request.Form["role"]); // Establish an employee model var employeeModel = new EmployeeModel(); // Conduct edit employeeModel.EditEmployee(employee); // Passes back to the view return(Redirect("Employee/Employee")); } else { // If not logged in return(Redirect("/login.html")); } }
public ActionResult EditEmployee(EmployeeModel employee) { var editEmp = EmployeeModel.EditEmployee(employee); return(Json(new { success = editEmp })); }
public ActionResult Edit(Employee employee, FormCollection data) { var currentUser = (User)Session["CurrentUser"]; var userName = string.Empty; if (currentUser != null) { userName = currentUser.User_Name; } var dateLastModified = DateTime.Now; var modifiedBy = userName; const bool isActive = true; const bool isDeleted = false; var auditTrail = new AuditTrailModel(); if (ModelState.IsValid) { var userModel = new UserModel(); var employeeModel = new EmployeeModel(); var updatedEmployee = employeeModel.EditEmployee(employee.Employee_Id, employee.User.First_Name, employee.User.Last_Name, employee.User.Initials, employee.User.Email_Address, employee.Persal_Number, employee.Head_Of_Department_Id, employee.Supervisor_Id, employee.Phone_Number, employee.Mobile_Phone_Number, employee.Gender_Id, employee.Race_Id, employee.ID_Number, employee.Job_Position_Id, employee.Paypoint_Id, employee.Service_Office_Id, employee.Salary_Level_Id, employee.Is_Shift_Worker, employee.Is_Casual_Worker, isActive, isDeleted, dateLastModified, modifiedBy, employee.Is_SocialWorker, employee.PracticeNumber, employee.Facility_Id ); if (updatedEmployee == null) { ViewBag.Message = "An Error Occured, Please contact Support"; return(View(employee)); } else { auditTrail.InsertAuditTrail(userName, "Update Employee Details", "Admin"); } // Link Selected Roles var roleIds = new List <int>(); if (employee.User.Posted_Roles != null) { foreach (var roleId in employee.User.Posted_Roles.Role_IDs) { var roleIdValue = int.Parse(roleId); roleIds.Add(roleIdValue); } } userModel.AddUserToRole(updatedEmployee.User.User_Id, roleIds); // Link Selected Groups var groupIds = new List <int>(); if (employee.User.Posted_Groups != null) { foreach (var groupId in employee.User.Posted_Groups.Group_IDs) { var groupIdValue = int.Parse(groupId); groupIds.Add(groupIdValue); } } userModel.AddUserToGroup(updatedEmployee.User.User_Id, groupIds); #region employee services and roles var employeeServicesM = new EmployeeServiceModel(); if (data["ServiceList"] != null) { //var value = data["ServiceList"].ToString(); string[] selectedServiceArray = data["ServiceList"].ToString().Split(','); employeeServicesM.Delete(Convert.ToInt32(updatedEmployee.Employee_Id)); foreach (string i in selectedServiceArray) { employeeServicesM.CreateEmployeeService(updatedEmployee.Employee_Id, Convert.ToInt32(i), currentUser.User_Id); } auditTrail.InsertAuditTrail(userName, "Update Employee Services" + ":" + data["ServiceList"], "Admin"); } var employeerolesM = new EmployeeRolesModel(); if (data["JobPositionList"] != null) { //var value2 = data["JobPositionList"].ToString(); string[] selectedRoleArray = data["JobPositionList"].ToString().Split(','); employeerolesM.DeleteEmployeeJobPositions(Convert.ToInt32(updatedEmployee.Employee_Id)); foreach (string i in selectedRoleArray) { employeerolesM.CreateEmployeeJobPosition(updatedEmployee.Employee_Id, Convert.ToInt32(i), currentUser.User_Id); } auditTrail.InsertAuditTrail(userName, "Update Employee Job position" + ":" + data["JobPositionList"], "Admin"); } #endregion return(RedirectToAction("Index", "Employee")); } return(View(employee)); }
public ActionResult Edit(EmployeeModel model) { model.EditEmployee(); return(RedirectToAction("Index")); }