Ejemplo n.º 1
0
        private void AddCertificates()
        {
            var allCitizens = citizenUserRepository.GetUsersAsQueryable();

            // Ensure that all citizens have a birth certificate.
            AddIfNotExistCertificateToCitizens(allCitizens, "Birth Certificate");

            // Ensure that 5 citizens have a diploma.
            var citizenLoginsWithDiploma = new List <string> {
                "Bill", "Musk", "Stroustrup", "Tsoi", "Chuck"
            };
            var citizenWithDiploma = citizenUserRepository.GetUsersByLogins(citizenLoginsWithDiploma);

            AddIfNotExistCertificateToCitizens(citizenWithDiploma, "Diploma of Higher Education");

            // Ensure that citizens have a policeman certificate.
            var citizenLoginsWithPoliceCertificate = new List <string> {
                "Chuck"
            };
            var policemen = citizenUserRepository.GetUsersByLogins(citizenLoginsWithPoliceCertificate);

            AddIfNotExistCertificateToCitizens(policemen, "Policeman Certificate");

            // Ensure that citizens have a doctor certificate.
            var citizenLoginsWithDoctorCertificate = new List <string> {
                "Tsoi"
            };
            var doctors = citizenUserRepository.GetUsersByLogins(citizenLoginsWithDoctorCertificate);

            AddIfNotExistCertificateToCitizens(doctors, "Doctor Certificate");
        }
Ejemplo n.º 2
0
        public List <CitizenUser> SearchUsers(string searchTerm)
        {
            var usersAsQueryable = citizenUserRepository.GetUsersAsQueryable();

            if (!string.IsNullOrWhiteSpace(searchTerm))
            {
                usersAsQueryable = usersAsQueryable.Where(user =>
                                                          user.FirstName.ToLower().Contains(searchTerm.ToLower()) ||
                                                          user.LastName.ToLower().Contains(searchTerm.ToLower()));
            }

            var foundUsers = usersAsQueryable.Take(10).OrderBy(user => user.FirstName).ToList();

            return(foundUsers);
        }