public static int CountUserByQuery(UserQuery query)
        {
            using (var context = new Intern4jobEntities())
            {
                var repository = new UserRepository(context);

                int count = repository.GetPageCount(item => _isMatch(item, query));
                return count;
            }
        }
 private static dynamic _orderByKey(User obj, UserQuery query)
 {
     if (string.IsNullOrEmpty(query.OrderByKey))
         return obj.Id;
     return obj.GetType().GetProperty(query.OrderByKey).GetValue(obj);
 }
        public static List<User> GetUserListByQuery(UserQuery query)
        {
            using (var context = new Intern4jobEntities())
            {
                var repository = new UserRepository(context);

                List<User> users = repository.GetPageList(item => _isMatch(item, query), item => _orderByKey(item, query), query.OrderByValue, query.Offset, query.Limit);
                return users;
            }
        }
        public static bool _isMatch(User obj, UserQuery query)
        {
            if (!string.IsNullOrEmpty(query.IdEqual) && !string.Equals(obj.Id, query.IdEqual))
                return false;
            if (!string.IsNullOrEmpty(query.IdNotEqual) && string.Equals(obj.Id, query.IdNotEqual))
                return false;

            if (!string.IsNullOrEmpty(query.NameEqual) && !string.Equals(obj.Name, query.NameEqual))
                return false;
            if (!string.IsNullOrEmpty(query.NameNotEqual) && string.Equals(obj.Name, query.NameNotEqual))
                return false;
            if (!string.IsNullOrEmpty(query.NameLike) && !obj.Name.Contains(query.NameLike))
                return false;

            if (!string.IsNullOrEmpty(query.StatusEqual) && !string.Equals(obj.Status, query.StatusEqual))
                return false;
            if (!string.IsNullOrEmpty(query.StatusNotEqual) && string.Equals(obj.Status, query.StatusNotEqual))
                return false;
            if ((query.StatusIn != null) && (query.StatusIn.Select(item => string.Equals(item, obj.Status)) == null))
                return false;
            if ((query.StatusNotIn != null) && (query.StatusNotIn.Select(item => string.Equals(item, obj.Status)) != null))
                return false;

            return true;
        }
 public static User GetUserById(string id4query)
 {
     UserQuery query = new UserQuery() { IdEqual = id4query };
     User userInDb = GetUserListByQuery(query).FirstOrDefault();
     return userInDb;
 }