예제 #1
0
        public IEnumerable<User> FindByCriteria(UserCriteria c)
        {
            return this.DbContext.Users.Where(o =>
                (!c.IdSrh.HasValue || o.Id.Equals(c.IdSrh.Value))
                && (!c.IdFromSrh.HasValue || o.Id >= c.IdFromSrh.Value)
                && (!c.IdToSrh.HasValue || o.Id <= c.IdToSrh.Value)
                && (String.IsNullOrEmpty(c.NameSrh) || o.Name.Contains(c.NameSrh))
                && (String.IsNullOrEmpty(c.PasswordSrh) || o.Password.Contains(c.PasswordSrh))
                && (String.IsNullOrEmpty(c.StatusSrh) || o.Status.Contains(c.StatusSrh))
                && (!c.LastLoginTimeSrh.HasValue || (o.LastLoginTime.HasValue 			&& o.LastLoginTime.Value.Equals(c.LastLoginTimeSrh.Value)))
                && (!c.LastLoginTimeFromSrh.HasValue || (o.LastLoginTime.HasValue 			&& o.LastLoginTime.Value >= c.LastLoginTimeFromSrh.Value))
                && (!c.LastLoginTimeToSrh.HasValue || (o.LastLoginTime.HasValue 			&& o.LastLoginTime.Value <= c.LastLoginTimeToSrh.Value))
                && (String.IsNullOrEmpty(c.LastLoginIPSrh) || o.LastLoginIP.Contains(c.LastLoginIPSrh))
                && (String.IsNullOrEmpty(c.DefaultUrlSrh) || o.DefaultUrl.Contains(c.DefaultUrlSrh))

            );
        }
예제 #2
0
        public PagedModel<User> FindByCriteria(UserCriteria c)
        {
            PagedModel<User> m = new PagedModel<User>();
            var r = this.Repository.FindByCriteria(c);
            if(!String.IsNullOrEmpty(c.sortname)){
            if(c.sortname.ToLower().Equals("id")){
                if(c.sortorder.ToLower().Equals("asc")){
                    r = r.OrderBy(o=>o.Id);
                }else{
                    r = r.OrderByDescending(o=>o.Id);
                }
            }
            if(c.sortname.ToLower().Equals("name")){
                if(c.sortorder.ToLower().Equals("asc")){
                    r = r.OrderBy(o=>o.Name);
                }else{
                    r = r.OrderByDescending(o=>o.Name);
                }
            }
            if(c.sortname.ToLower().Equals("password")){
                if(c.sortorder.ToLower().Equals("asc")){
                    r = r.OrderBy(o=>o.Password);
                }else{
                    r = r.OrderByDescending(o=>o.Password);
                }
            }
            if(c.sortname.ToLower().Equals("status")){
                if(c.sortorder.ToLower().Equals("asc")){
                    r = r.OrderBy(o=>o.Status);
                }else{
                    r = r.OrderByDescending(o=>o.Status);
                }
            }
            if(c.sortname.ToLower().Equals("lastlogintime")){
                if(c.sortorder.ToLower().Equals("asc")){
                    r = r.OrderBy(o=>o.LastLoginTime);
                }else{
                    r = r.OrderByDescending(o=>o.LastLoginTime);
                }
            }
            if(c.sortname.ToLower().Equals("lastloginip")){
                if(c.sortorder.ToLower().Equals("asc")){
                    r = r.OrderBy(o=>o.LastLoginIP);
                }else{
                    r = r.OrderByDescending(o=>o.LastLoginIP);
                }
            }
            if(c.sortname.ToLower().Equals("defaulturl")){
                if(c.sortorder.ToLower().Equals("asc")){
                    r = r.OrderBy(o=>o.DefaultUrl);
                }else{
                    r = r.OrderByDescending(o=>o.DefaultUrl);
                }
            }

            }

            m.RecordCount = r.Count();
            if (c.pagesize.HasValue) {
                int page = c.page ?? 1;
                int pageCount = m.RecordCount / c.pagesize.Value;
                if (m.RecordCount % c.pagesize.Value > 0) {
                    pageCount++;
                }
                int skip = (page - 1) * c.pagesize.Value;
                if (skip > 0) {
                    r = r.Skip(skip);
                }
                r = r.Take(c.pagesize.Value);
            }

            m.Data = r.ToList();
            return m;
        }