コード例 #1
0
 public void GetUsers_Default_ReturnsEmployeesWithSiteAccess()
 {
     var query = new UserQuery() { RoleName = "Employee", HasSiteAccess = true };
     var users = repository.GetUsers(query);
     Assert.IsNotNull(users);
     Assert.AreEqual(11, users.Count);
 }
コード例 #2
0
 public void GetUsers_ReturnsAdministrators()
 {
     var query = new UserQuery() { RoleName = "Administrator" };
     var users = repository.GetUsers(query);
     Assert.IsNotNull(users);
     Assert.AreEqual(3, users.Count);
 }
コード例 #3
0
        public IList<Employee> GetUsers(UserQuery query)
        {
            var criteria = Session.CreateCriteria<Employee>();

            if (query.HasSiteAccess.HasValue) criteria.Add(Expression.Eq("IsEmployed", query.HasSiteAccess.Value));
            if (!string.IsNullOrEmpty(query.Name)) criteria.Add(Expression.Like("Name", string.Format("%{0}%", query.Name)));
            if (!string.IsNullOrEmpty(query.RoleName)) criteria.Add(Expression.Eq("RoleName", query.RoleName));

            if (string.IsNullOrEmpty(query.SortBy))
                criteria.AddOrder(new Order("Name", true));
            else
                criteria.AddOrder(new Order(query.SortBy, (query.SortDirection != null && query.SortDirection.Equals("asc", StringComparison.InvariantCultureIgnoreCase))));

            return criteria.List<Employee>();
        }