예제 #1
0
        public LoginDTO GetEmployeeLoginByUsernameAndPassword(string username, string password)
        {
            //Hash password first
            if (password == null)
            {
                return(null);
            }

            string hashedPassword = HashPassword(password);

            Employee e = employeeRepo.FindBy(x => x.Username == username && x.Password == hashedPassword).SingleOrDefault();

            if (e == null) // no such user
            {
                return(null);
            }
            else
            {
                Session newSession = new Session()
                {
                    EmployeeId = e.Id, GUID = Guid.NewGuid().ToString(), LogInDateTime = DateTime.Now
                };
                sessionRepo.Create(newSession);

                //check if cover head?
                int role = departmentCoverEmployeeRepo.FindOneBy(x => x.EmployeeId == e.Id && x.Status == "ACTIVE" && DbFunctions.TruncateTime(x.FromDate) <= DateTime.Now && DbFunctions.TruncateTime(x.ToDate) >= DateTime.Now) != null ? (int)Enums.Roles.DepartmentCoverHead : e.RoleId;

                //set attributes
                LoginDTO loginDTO = new LoginDTO()
                {
                    EmployeeId = e.Id, RoleId = role, SessionGuid = newSession.GUID, Department = e.Department.DepartmentName
                };
                return(loginDTO);
            }
        }
        // method to get all employees in Departments
        public List <Employee> RetrieveAllEmployeesInAssignedDepartmentList(List <Department> departmentList)
        {
            List <Employee> employeesInAssignedDepartmentList = new List <Employee>();

            foreach (Department dp in departmentList)
            {
                List <Employee> employeeList = (List <Employee>)employeeRepo.FindBy(x => x.DepartmentId == dp.Id);
                foreach (Employee empl in employeeList)
                {
                    Employee em = empl;
                    employeesInAssignedDepartmentList.Add(em);
                }
            }
            return(employeesInAssignedDepartmentList);
        }