// 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"); } }
// Returns a complete list of employees public ActionResult Employees() { // Null handling if (Session["loggedInState"] == null) { return Redirect("/403.html"); } // If logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Creates models var employeeModel = new EmployeeModel(); var departmentModel = new DepartmentModel(); var roleModel = new RoleModel(); var depotModel = new DepotModel(); // Gets the complete list List<Employee> el = employeeModel.GetEmployeesList(); if (el.Count != 0) { // Attaches associated department / role to employee foreach (var employee in el) { // Acquires, and adds the employee depot Depot depot = null; if (employee.Depot != 0) { depot = depotModel.SearchDepot(employee.Depot); } // Acquires, and adds the employee department Department dept = null; if (employee.Dept != 0) { dept = departmentModel.SearchDepartment(employee.Dept); } // Acquires, and adds the employee role Role role = null; if (employee.Role != 0) { role = roleModel.SearchRoles(employee.Role); } // Appends objects to employee employee.DepotO = depot; employee.Department = dept; employee.RoleO = role; } // Returns the list return View(el); } else { return Redirect("/403.html"); } } else { // If not logged in return Redirect("/login.html"); } }