示例#1
0
        public static Dto.Employee ToModel(DBE.Employee employee)
        {
            if (employee == null)
            {
                return(null);
            }

            return(new Dto.Employee
            {
                EmployeeId = employee.Emp_Id,
                Name = employee.Name,
                FirstName = employee.FirstName,
                LastName = employee.LastName,
                NtLogin = employee.NTLogin,
                Active = employee.Empl_Status == "A",
                Badge = employee.Badge,
                Email = employee.EmailAddress,
                Phone = employee.WorkPhone,
                JobTitle = employee.JobTitle
            });
        }
        public IQueryable <EM.Employee> GetEmployees(EM.Employee employeeCriteria)
        {
            Expression <Func <EM.Employee, bool> > whereClause = null;
            var exp = new Expression <Func <EM.Employee, bool> > [20];

            if (employeeCriteria.Badge != null)
            {
                exp[0] = m => m.Badge != null && m.Badge.Contains(employeeCriteria.Badge);
            }
            if (employeeCriteria.Name != null)
            {
                exp[1] = m => m.Name != null && m.Name.Contains(employeeCriteria.Name);
            }
            if (employeeCriteria.FirstName != null)
            {
                exp[2] = m => m.FirstName != null && m.FirstName.Contains(employeeCriteria.FirstName);
            }
            if (employeeCriteria.LastName != null)
            {
                exp[3] = m => m.LastName != null && m.LastName.Contains(employeeCriteria.LastName);
            }
            if (employeeCriteria.MiddleName != null)
            {
                exp[4] = m => m.MiddleName != null && m.MiddleName.Contains(employeeCriteria.MiddleName);
            }
            if (employeeCriteria.BirthDate != null)
            {
                exp[5] = m => m.BirthDate != null && m.BirthDate != null && m.BirthDate.Value == employeeCriteria.BirthDate.Value;
            }
            if (employeeCriteria.Address01 != null)
            {
                exp[6] = m => m.Address01 != null && m.Address01.Contains(employeeCriteria.Address01);
            }
            if (employeeCriteria.Address02 != null)
            {
                exp[7] = m => m.Address02 != null && m.Address02.Contains(employeeCriteria.Address02);
            }
            if (employeeCriteria.City != null)
            {
                exp[8] = m => m.City != null && m.City.Contains(employeeCriteria.City);
            }
            if (employeeCriteria.State != null)
            {
                exp[9] = m => m.State != null && m.State.Contains(employeeCriteria.State);
            }
            if (employeeCriteria.PreferredPhone != null)
            {
                exp[10] = m => m.PreferredPhone != null && m.PreferredPhone.Contains(employeeCriteria.PreferredPhone);
            }
            if (employeeCriteria.CellPhone != null)
            {
                exp[11] = m => m.CellPhone != null && m.CellPhone.Contains(employeeCriteria.CellPhone);
            }
            if (employeeCriteria.WorkPhone != null)
            {
                exp[12] = m => m.WorkPhone != null && m.WorkPhone.Contains(employeeCriteria.WorkPhone);
            }
            if (employeeCriteria.EmailAddress != null)
            {
                exp[13] = m => m.EmailAddress != null && m.EmailAddress.Contains(employeeCriteria.EmailAddress);
            }
            if (employeeCriteria.DeptName != null)
            {
                exp[14] = m => m.DeptName != null && m.DeptName.Contains(employeeCriteria.DeptName);
            }
            if (employeeCriteria.JobTitle != null)
            {
                exp[15] = m => m.JobTitle != null && m.JobTitle.Contains(employeeCriteria.JobTitle);
            }
            if (employeeCriteria.NTLogin != null)
            {
                exp[16] = m => m.NTLogin != null && m.NTLogin.Contains(employeeCriteria.NTLogin);
            }
            if (employeeCriteria.Empl_Status != null)
            {
                exp[17] = m => m.Empl_Status != null && m.Empl_Status == employeeCriteria.Empl_Status;
            }

            foreach (var t in exp)
            {
                if (t == null)
                {
                    continue;
                }
                whereClause = whereClause == null ? t : whereClause.And(t);
            }

            var contacts = ((EmployeeEntities)Context).Employees.AsQueryable();

            if (whereClause != null)
            {
                contacts = contacts.Where(whereClause);
            }

            return(contacts.OrderBy(c => c.Name));
        }