Example #1
0
        // Deletes a role
        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 roleID = int.Parse(RouteData.Values[""].ToString());

                // Establishes role model
                RoleModel roleModel = new RoleModel();

                // Deletes the role from the database using the ID
                roleModel.DeleteRole(roleID);

                return Redirect("/..role");
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Example #2
0
        // GET: Role
        public ActionResult Create()
        {
            // Ensures logged in
            if (Session["loggedInState"] == null)
            {
                return Redirect("/403.html");
            }

             // Checks if logged in
            bool state = (bool)Session["loggedInState"];
            if (state == true)
            {
                // Establishes role model
                RoleModel roleModel = new RoleModel();

                // Holds the new role
                Role newRole = new Role();

                // Stored details for the role
                newRole.Title = Request.Form[0];

                // Adds the object to the database
                roleModel.CreateRole(newRole);

                // Returns the created role to view
                return View(newRole);
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Example #3
0
        public ActionResult Edit()
        {
            int id = int.Parse(RouteData.Values["ID"].ToString());

            var roleEditor = new RoleModel();

            Role editingRole = roleEditor.SearchRoles(id);

            return View(editingRole);
        }
Example #4
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");
            }
        }
Example #5
0
        // Controller for modification of a role
        public ActionResult EditRole()
        {
            // Null handling
            if (Session["loggedInState"] == null)
            {
                return Redirect("/403.html");
            }

            // Checks if logged in
            bool state = (bool)Session["loggedInState"];
            if (state == true)
            {
                // Creates a role placeholder
                var role = new Role();

                // Setup role edit
                role.Id = int.Parse(Request.Form["id"]);
                role.Title = Request.Form["title"];

                // Establishes role model
                var roleModel = new RoleModel();

                // Conduct edit
                roleModel.EditRole(role);

                // Passes back to the view
                return Redirect("/Role/");
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Example #6
0
        // Lists all roles
        public ActionResult Index()
        {
            // Null handling
            if (Session["loggedInState"] == null)
            {
                return Redirect("/403.html");
            }

            bool state = (bool)Session["loggedInState"];
            if (state == true)
            {
                // Creates an employee model
                var rm = new RoleModel();

                // Gets the complete list
                var rl = rm.ListRoles();

                // Returns the list
                return View(rl);
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }