// Returns a list of all departments public ActionResult Department() { // Null handling if (Session["loggedInState"] == null) { Redirect("403.html"); } // If logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Acquires complete department list var dm = new DepartmentModel(); var dl = dm.GetDepartmentsList(); // Return list of departments return View(dl); } else { // If not logged in return Redirect("/login.html"); } }
// 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"); } }
public ActionResult EditDepartment() { // Null handling if (Session["loggedInState"] == null) { return Redirect("/403.html"); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Creates an department placeholder var d = new Department(); // Setup address edit d.Id = int.Parse(Request.Form["id"]); d.Title = Request.Form["title"]; d.Head = int.Parse(Request.Form["head"]); d.Address = int.Parse(Request.Form["address"]); // Establish department model var dm = new DepartmentModel(); // Conduct edit dm.EditDepartment(d); // TODO: Redirect to appropriate page (Add address?) // Passes back to the view return View(); } else { // If not logged in return Redirect("/login.html"); } }
// GET: Department public ActionResult Index() { // Ensures logged in if (Session["loggedInState"] == null) { return Redirect("/403.html"); } // Checks if logged in bool state = (bool)Session["loggedInState"]; if (state == true) { // Establishes a department model DepartmentModel departmentModel = new DepartmentModel(); // Holds the new department Department newDepartment = new Department(); // Stored details for the department newDepartment.Title = Request.Form[1]; newDepartment.Head = int.Parse(Request.Form[2]); newDepartment.Address = int.Parse(Request.Form[3]); // Commences save to database departmentModel.CreateNewDepartment(newDepartment); // Return created department to view return View(newDepartment); } 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"); } }