Ejemplo n.º 1
0
 public ActionResult AddEmployeeToDepartment(ED.AddEmployeeToDepartmentForm form)
 {
     if (ModelState.IsValid)
     {
         DepartmentService.AddEmployeeDepartment(form.SelectedEmployeeId, form.SelectedDepartmentId, SessionUser.GetUser().Id);
         return(RedirectToAction("Details", "Employee", new { id = form.SelectedEmployeeId }));
     }
     return(RedirectToAction("AddEmployeeToDepartment"));
 }
Ejemplo n.º 2
0
        public ActionResult AddEmployeeToDepartment(int id)
        {
            int My_Id = SessionUser.GetUser().Id;
            IEnumerable <C.Department> MyDepartments = new List <C.Department>();

            if (AuthService.IsAdmin(My_Id))
            {
                MyDepartments = DepartmentService.GetAllActive();
            }
            else
            {
                MyDepartments = DepartmentService.GetHeadOfDepartmentActiveDepartments(My_Id);
            }
            if (!MyDepartments.Any())
            {
                return(RedirectToAction("Index", "Employee"));
            }
            IEnumerable <C.Department> EmpDepartments = DepartmentService.GetEmployeeDepartments(id);

            List <SelectListItem> DepartmentList = new List <SelectListItem>();

            foreach (C.Department dep in MyDepartments)
            {
                if (!EmpDepartments.Any(empDep => empDep.Id == dep.Id))
                {
                    DepartmentList.Add(new SelectListItem
                    {
                        Text  = dep.Title,
                        Value = dep.Id.ToString()
                    });
                }
            }
            ED.AddEmployeeToDepartmentForm form = new ED.AddEmployeeToDepartmentForm
            {
                SelectedEmployeeId = id,
                DepartmentList     = DepartmentList
            };
            return(View(form));
        }