Beispiel #1
0
 public ActionResult RemoveEmployeeFromDepartment(ED.RemoveEmployeeFromDepartmentForm form)
 {
     if (ModelState.IsValid)
     {
         DepartmentService.RemoveEmployeeDepartment(form.SelectedEmployeeId, form.SelectedDepartmentId, SessionUser.GetUser().Id);
         return(RedirectToAction("Details", "Employee", new { id = form.SelectedEmployeeId }));
     }
     return(RedirectToAction("RemoveEmployeeFromDepartment"));
 }
Beispiel #2
0
        public ActionResult RemoveEmployeeFromDepartment(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 DepartmentService.GetEmployeeDepartments(id))
            {
                if (MyDepartments.Any(MyDep => MyDep.Id == dep.Id))
                {
                    DepartmentList.Add(new SelectListItem
                    {
                        Text  = dep.Title,
                        Value = dep.Id.ToString()
                    });
                }
            }
            ED.RemoveEmployeeFromDepartmentForm form = new ED.RemoveEmployeeFromDepartmentForm
            {
                SelectedEmployeeId = id,
                DepartmentList     = DepartmentList
            };

            return(View(form));
        }