// 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"); } }