Ejemplo n.º 1
0
        public ActionResult ViewDepartments()
        {
            //Check if user is logged in then redirect him to gome page
            if (Session["Email"] == null)
            {
                return(RedirectToAction("SignIn", "User"));
            }
            else
            {
                //View all departments with their manager if it is assigned
                var data = DepartmentProcessor.LoadDepartments();
                List <DepartmentModel> departments = new List <DepartmentModel>();

                foreach (var row in data)
                {
                    departments.Add(new DepartmentModel
                    {
                        DepartmentName        = row.DepName,
                        DepartmentDescription = row.DepDescription,
                        ManagerName           = row.EmpName
                    });
                }

                return(View(departments));
            }
        }
Ejemplo n.º 2
0
        public ActionResult CreateEmployee()
        {
            //Check if user is logged in then redirect him to gome page
            if (Session["Email"] == null)
            {
                return(RedirectToAction("SignIn", "User"));
            }
            else
            {
                //Load all departments to display in drop down menu
                var data = DepartmentProcessor.LoadDepartments();
                List <DepartmentItemsModel> departments = new List <DepartmentItemsModel>();

                foreach (var row in data)
                {
                    departments.Add(new DepartmentItemsModel
                    {
                        Id   = row.Id,
                        Name = row.DepName,
                    });
                }

                var model = new EmployeeModel();
                model.Departments = departments;

                return(View(model));
            }
        }
Ejemplo n.º 3
0
 public ActionResult CreateDepartment(DepartmentModel model)
 {
     //Checks if user inputs are valid then create new department
     if (ModelState.IsValid)
     {
         int recordsCreated = DepartmentProcessor.CreateDepartment(model.DepartmentName,
                                                                   model.DepartmentDescription);
         if (recordsCreated > 1)
         {
             return(RedirectToAction("ViewDepartments"));
         }
         return(RedirectToAction("ViewDepartments"));
     }
     return(View());
 }