Example #1
0
        // Controller to redirect to the edit page - ANDREW DID THIS - TRISTAN FIXED THIS
        public ActionResult edit()
        {
            // Null handling
            if (Session["loggedInState"] == null)
            {
                return Redirect("/403.html");
            }

            // Checks if logged in
            bool state = (bool)Session["loggedInState"];
            if (state == true)
            {
                // Get the employee ID
                int employeeID = int.Parse(RouteData.Values["id"].ToString());

                // Create a new EmployeeModel
                EmployeeModel employeeModel = new EmployeeModel();

                // Finds employee
                Employee employee = employeeModel.SearchEmployee(employeeID);

                // Return employee to view
                return View(employee);
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Example #2
0
        // Deletes an employee
        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 employeeID = int.Parse(RouteData.Values["id"].ToString());

                // Establishes employee model
                EmployeeModel employeeModel = new EmployeeModel();

                // Deletes the employee from the database using the ID
                employeeModel.DeleteEmployee(employeeID);

                // Return to the employee page
                return Redirect("/Employee/Employees");
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Example #3
0
        // Create employee
        public int create(String firstname, String lastname, DateTime DOB, String contactNum,
                          DateTime startDate, int dept, int depot, int role)
        {
            // Establishes model
            EmployeeModel employeeModel = new EmployeeModel();

            // Holds the new employee
            Employee newEmployee = new Employee();

            // Stored details for the employee
            newEmployee.Firstname = firstname;
            newEmployee.Lastname = lastname;
            newEmployee.DOB = DOB;
            newEmployee.ContactNumber = contactNum;
            newEmployee.Startdate = startDate;
            newEmployee.Dept = dept;
            newEmployee.Depot = depot;
            newEmployee.Role = role;

            // Adds the object to the database
            int employeeID = employeeModel.NewEmployee(newEmployee);

            // Return the employeeID
            return employeeID;
        }
Example #4
0
        // 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");
            }
        }
Example #5
0
        // 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");
            }
        }
Example #6
0
        // 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");
            }
        }
Example #7
0
        // GET: Employee
        public ActionResult Index()
        {
            // Null handling
            if (Session["loggedInState"] == null)
            {
                return Redirect("/403.html");
            }

            // Checks if logged in
            bool state = (bool)Session["loggedInState"];
            if (state == true)
            {
                // Establishes employee model
                EmployeeModel employeeModel = new EmployeeModel();

                // Holds the new employee
                Employee newEmployee = new Employee();

                // Stored details for the employee
                newEmployee.Firstname = Request.Form[0];
                newEmployee.Lastname = Request.Form[1];
                newEmployee.DOB = DateTime.Parse(Request.Form[2]);
                newEmployee.ContactNumber = Request.Form[3];
                newEmployee.Startdate = DateTime.Parse(Request.Form[4]);
                newEmployee.Dept = int.Parse(Request.Form[5]);
                newEmployee.Depot = int.Parse(Request.Form[6]);
                newEmployee.Role = int.Parse(Request.Form[7]);

                // Adds the object to the database
                employeeModel.NewEmployee(newEmployee);

                // Return created employee to view
                return View(newEmployee);
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Example #8
0
        // 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");
            }
        }