Exemplo n.º 1
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");
            }
        }
Exemplo n.º 2
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");
            }
        }
Exemplo n.º 3
0
        // Controller for modification of a depot
        public ActionResult EditDepot()
        {
            // 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 depot = new Depot();

                // Setup role edit
                depot.ID = int.Parse(Request.Form["id"]);
                depot.ManagerID = int.Parse(Request.Form["managerID"]);
                depot.DepotName = Request.Form["depotName"];
                depot.FloorSpace = int.Parse(Request.Form["floorSpace"]);
                depot.NumVehicles = int.Parse(Request.Form["numVehicles"]);

                // Establishes role model
                var depotModel = new DepotModel();

                // Conduct edit
                depotModel.EditDepot(depot);

                // Passes back to the view
                return View();
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Exemplo n.º 4
0
        // GET: Depot
        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 depot model
                DepotModel depotModel = new DepotModel();

                // Holds the new depot
                Depot newDepot = new Depot();

                // Stored details for the depot
                newDepot.AddressID = int.Parse(Request.Form[0]);
                newDepot.ManagerID = int.Parse(Request.Form[1]);
                newDepot.DepotName = Request.Form[2];
                newDepot.FloorSpace = Double.Parse(Request.Form[3]);
                newDepot.NumVehicles = int.Parse(Request.Form[4]);

                // Adds the object to the database
                depotModel.CreateDepot(newDepot);

                // Return created department to view
                return View(newDepot);
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }