public Employee setApprover(string userId)
        {
            Departments department = findDepartmentByEmployee(userId);
            //To extract authorization that is from the dept and have overlapping dates with Today
            EmployeeAuthorize employeeAuthorize = dbcontext.employeeAuthorizes
                                                  .Where(x => DateTime.Now >= x.startDate &&
                                                         DateTime.Now <= x.endDate &&
                                                         x.DepartmentsId == department.Id).FirstOrDefault();

            if (employeeAuthorize != null)
            {
                return(findEmployeeById(employeeAuthorize.EmployeeId));
            }
            return(dbcontext.employees.Where(x => x.DepartmentsId == department.Id && x.Role == Role.DEPT_HEAD).FirstOrDefault());
        }
        public void createEmployeeAuthorization(string employeeName, string SD, string ED)
        {
            DateTime startDate = DateTime.Parse(SD);
            DateTime endDate   = DateTime.Parse(ED);
            Employee employee  = dbcontext.employees.Where(x => x.Name == employeeName).FirstOrDefault();
            //To extract authorization that is from the dept and have overlapping dates
            List <EmployeeAuthorize> existEmpAuthorize = dbcontext.employeeAuthorizes.Where(x => x.DepartmentsId == employee.DepartmentsId && x.startDate <= endDate && x.endDate >= startDate).ToList();

            if (existEmpAuthorize.Count > 0)
            {
                dbcontext.employeeAuthorizes.RemoveRange(existEmpAuthorize);                              //Remove any authorization that have overlaps in dates
            }
            EmployeeAuthorize newAuthorize = new EmployeeAuthorize();

            newAuthorize.Id            = Guid.NewGuid().ToString();
            newAuthorize.EmployeeId    = employee.Id;
            newAuthorize.startDate     = startDate;
            newAuthorize.endDate       = endDate;
            newAuthorize.DepartmentsId = employee.DepartmentsId;
            dbcontext.employeeAuthorizes.Add(newAuthorize);
            dbcontext.SaveChanges();
        }
        public bool IsAuthorizer(string userId)
        {
            Departments department = findDepartmentByEmployee(userId);
            //To extract authorization that is from the dept and have overlapping dates with Today
            EmployeeAuthorize employeeAuthorize = dbcontext.employeeAuthorizes
                                                  .Where(x => DateTime.Now >= x.startDate &&
                                                         DateTime.Now <= x.endDate &&
                                                         x.DepartmentsId == department.Id).FirstOrDefault();

            if (employeeAuthorize != null && employeeAuthorize.EmployeeId == userId)
            {
                return(true);
            }
            //If there is no Authorize Employee on the day and login user is dept head
            else if (employeeAuthorize == null && department.Employees.Where(x => x.Role == Role.DEPT_HEAD).FirstOrDefault().Id == userId)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }