示例#1
0
        public IEnumerable<UserViewModel> SearchUsers(UserSearchModel searchModel, string userId)
        {
            var usersDb = _userRepository.GetUsers(userId).ToList();
            var userList = ModelConverters.ToUserViewModelList(usersDb);
            var result = new List<UserViewModel>();

            if (string.IsNullOrEmpty(searchModel.Country) == false)
            {
                result.AddRange(userList.Where(m => m.Country != null && m.Country.ToLower().Contains(searchModel.Country.ToLower())));
            }

            if (string.IsNullOrEmpty(searchModel.City) == false)
            {
                result.AddRange(userList.Where(m => m.City != null && m.City.ToLower().Contains(searchModel.City.ToLower())));
            }

            if (string.IsNullOrEmpty(searchModel.Genres) == false)
            {
                result.AddRange(userList.Where(m => m.BestGenres != null && m.BestGenres.ToLower().Contains(searchModel.Genres.ToLower())));
            }

            if (string.IsNullOrEmpty(searchModel.Atrists) == false)
            {
                result.AddRange(
                    userList.Where(m =>
                        m.BestVocalist != null && m.BestVocalist.ToLower().Contains(searchModel.Atrists.ToLower()) ||
                         m.BestForeignArtist != null && m.BestForeignArtist.ToLower().Contains(searchModel.Atrists.ToLower()) ||
                         m.BestNativeArtist != null && m.BestNativeArtist.ToLower().Contains(searchModel.Atrists.ToLower()))
                         );
            }

            if (string.IsNullOrEmpty(searchModel.FirstName) == false)
            {
                result.AddRange(userList.Where(m => m.FirstName != null && m.FirstName.ToLower().Contains(searchModel.FirstName.ToLower())));
            }

            if (string.IsNullOrEmpty(searchModel.LastName) == false)
            {
                result.AddRange(userList.Where(m => m.LastName != null && m.LastName.ToLower().Contains(searchModel.LastName.ToLower())));
            }

            if (searchModel.BirthDate.HasValue)
            {
                result.AddRange(userList.Where(m => m.BirthDate.Date == searchModel.BirthDate.Value.Date));
            }

            return result;
        }
示例#2
0
 public JsonResult SearchUsers(UserSearchModel searchModel)
 {
     return Json(_userService.SearchUsers(searchModel, User.Identity.GetUserId()), JsonRequestBehavior.AllowGet);
 }