Ejemplo n.º 1
0
        public IPagedList<User> GetUsersPaged(UserSearchQuery searchQuery)
        {
            var query = _session.QueryOver<User>();

            if (!string.IsNullOrWhiteSpace(searchQuery.Email))
                query =
                    query.Where(
                        user =>
                            user.Email.IsInsensitiveLike(searchQuery.Email, MatchMode.Anywhere));

            if (!string.IsNullOrWhiteSpace(searchQuery.FirstName))
                query =
                    query.Where(
                        user =>
                            user.FirstName.IsInsensitiveLike(searchQuery.FirstName, MatchMode.Anywhere));

            if (!string.IsNullOrWhiteSpace(searchQuery.LastName))
                query =
                    query.Where(
                        user =>
                            user.LastName.IsInsensitiveLike(searchQuery.LastName, MatchMode.Anywhere));

            if (searchQuery.UserRoleId != null)
            {
                UserRole role = null;
                query = query.JoinAlias(user => user.Roles, () => role).Where(() => role.Id == searchQuery.UserRoleId);
            }

            return query.Paged(searchQuery.Page);
        }
Ejemplo n.º 2
0
        public void UserController_Index_ShouldReturnThePassedQueryAsTheModel()
        {
            var userSearchQuery = new UserSearchQuery();

            ActionResult actionResult = _userController.Index(userSearchQuery);

            actionResult.As<ViewResult>().Model.Should().BeSameAs(userSearchQuery);
        }
Ejemplo n.º 3
0
        public void UserController_Index_ShouldCallUserServiceGetUsersPaged()
        {
            var userSearchQuery = new UserSearchQuery();

            _userController.Index(userSearchQuery);

            A.CallTo(() => _userSearchService.GetUsersPaged(userSearchQuery)).MustHaveHappened();
        }
Ejemplo n.º 4
0
        public void UserController_Index_ShouldReturnTheResultOfServiceCallAsViewData()
        {
            var users = new StaticPagedList<User>(new List<User>(), 1, 1, 0);
            var userSearchQuery = new UserSearchQuery();
            A.CallTo(() => _userSearchService.GetUsersPaged(userSearchQuery)).Returns(users);

            ActionResult actionResult = _userController.Index(userSearchQuery);

            _userController.ViewData["users"].Should().Be(users);
        }
Ejemplo n.º 5
0
 public ActionResult Index(UserSearchQuery searchQuery)
 {
     ViewData["users"] = _userSearchService.GetUsersPaged(searchQuery);
     ViewData["roles"] = _userSearchService.GetAllRoleOptions();
     return View(searchQuery);
 }