public static List <Person> GetFilteredData(string firstName, string lastName, string office, string department, bool active)
        {
            IQueryable <Person> oDataQuery = StaticCache.GetEmployees().AsQueryable();

            if (firstName.Trim().Length > 0)
            {
                oDataQuery = oDataQuery.Where(a => a.FirstName.StartsWith(firstName, true, CultureInfo.InvariantCulture));
            }

            if (lastName.Trim().Length > 0)
            {
                oDataQuery = oDataQuery.Where(a => a.LastName.StartsWith(lastName, true, CultureInfo.InvariantCulture));
            }

            if (office.Trim().Length > 0)
            {
                oDataQuery = oDataQuery.Where(a => a.Office.Id.ToString().Equals(office.ToString()));
            }

            if (department.Trim().Length > 0)
            {
                oDataQuery = oDataQuery.Where(a => a.Department.Id.ToString().Equals(department.ToString()));
            }

            return(oDataQuery.ToList());
        }
示例#2
0
        public static Person FindPersonById(string Id)
        {
            List <Person> employees = StaticCache.GetEmployees();

            //Person foundPerson = (Person)employees.FirstOrDefault(a => a.EmployeeNumber.Equals(Id));
            return(employees.Find(a => a.EmployeeNumber.Equals(Id)));
        }
 public static object GetPersonById(string id)
 {
     try
     {
         List <Person> employees = StaticCache.GetEmployees();
         var           filtered  = employees.Where(x => x.EmployeeNumber.ToString() == id).ToList();
         return(JsonConvert.SerializeObject(filtered, Formatting.Indented));
     }
     catch (Exception exception)
     {
         throw new Exception(string.Format("Error Loading Instance with id {0}, Error: {1}", id, exception));
     }
 }