// GET: Admin/Department
        public ActionResult Index()
        {
            DepartmentService         departRepo  = new DepartmentService();
            IEnumerable <Department>  departments = departRepo.Get();
            List <DepartmentListItem> finalList   = new List <DepartmentListItem>();

            foreach (Department department in departments)
            {
                AdminService       adminRepo      = new AdminService();
                DepartmentListItem departmentList = new DepartmentListItem(department, adminRepo.Get(department.AdminId));
                finalList.Add(departmentList);
            }
            return(View(finalList));
        }
        /*
         * //GET : Admin/Department/Register/5
         * public ActionResult Register(int departmentId)
         * {
         *  EmployeeService repoEmployee = new EmployeeService();
         *  return View();
         * }
         *
         * //POST : Admin/Department/Register/5
         * [HttpPost]
         * public ActionResult Register(int dempartmentId,SelectEmployee employee)
         * {
         *  try
         *  {
         *      if (ModelState.IsValid)
         *      {
         *          DepartmentService repoDepart = new DepartmentService();
         *          repoDepart.Register(employee.Id, dempartmentId);
         *          return RedirectToAction("Index");
         *      }
         *      return View();
         *  }
         *  catch (Exception)
         *  {
         *      return View();
         *  }
         * }*/

        // GET: Admin/Department/Delete/5
        public ActionResult Delete(int id)
        {
            EmployeeService repoEmployee = new EmployeeService();

            if (repoEmployee.GetByDepartment(id).Count() != 0)
            {
                return(RedirectToAction("Details", new { id = id }));
            }
            DepartmentService  departRepo = new DepartmentService();
            Department         department = departRepo.Get(id);
            AdminService       adminRepo  = new AdminService();
            DepartmentListItem departList = new DepartmentListItem(department, adminRepo.Get(department.AdminId));

            return(View(departList));
        }
        public static List <DepartmentListItem> DepartmentList()
        {
            List <DepartmentListItem> Result = new List <DepartmentListItem>();
            DepartmentListItem        listItem;

            foreach (var item in unitOfWork.Department.Get())
            {
                listItem                = new DepartmentListItem();
                listItem.deptId         = item.DeptId;
                listItem.deptName       = item.deptname;
                listItem.businessUnitId = item.BusinessUnits.BusId;
                Result.Add(listItem);
            }
            return(Result);
        }
        public static List <DepartmentListItem> DepartmentById(int?id)
        {
            if (id == null)
            {
                return(null);
            }
            List <DepartmentListItem> Result = new List <DepartmentListItem>();
            DepartmentListItem        listItem;

            foreach (var item in unitOfWork.GetDbContext().departments.Where(x => x.BunitId == id).OrderBy(x => x.deptname))
            {
                listItem                = new DepartmentListItem();
                listItem.deptId         = item.DeptId;
                listItem.deptName       = item.deptname;
                listItem.businessUnitId = item.BunitId;
                Result.Add(listItem);
            }
            return(Result);
        }
 public ActionResult Delete(int id, DepartmentListItem departmentList)
 {
     try
     {
         EmployeeService        employeeRepo = new EmployeeService();
         IEnumerable <Employee> empl         = employeeRepo.GetByDepartment(id);
         if (empl.Count() == 0)
         {
             DepartmentService departRepo = new DepartmentService();
             if (departRepo.Delete(id))
             {
                 return(RedirectToAction("Index"));
             }
         }
         return(View(id));
     }
     catch
     {
         return(View(id));
     }
 }