Exemplo n.º 1
0
        /// <summary>
        /// 获取全部的数据
        /// </summary>
        /// <param name="ColumnType"></param>
        /// <returns></returns>
        public virtual IList <Columns> GetColumnsList(ColumnSearch search)
        {
            var query = _columnsRepository.Table;

            query = query.Where(c => c.ColumnType == (int)search.columnType);
            //按keys查询
            if (!string.IsNullOrEmpty(search.columnKeys))
            {
                query = query.Where(c => c.ColumnKey == search.columnKeys);
            }
            //按标题查找
            if (!string.IsNullOrEmpty(search.columnTitle))
            {
                query = query.Where(c => c.ColumnTitle.Contains(search.columnTitle) || c.Subtitle.Contains(search.columnTitle));
            }
            if (search.createdFromUtc != DateTime.MinValue)
            {
                //查询的数据不超过一年
                var searchtime = search.createdFromUtc;
                if (search.createdFromUtc.AddYears(1) > DateTime.UtcNow)
                {
                    searchtime = DateTime.UtcNow.AddYears(-1);
                }
                query = query.Where(c => c.CreatedOnUtc >= searchtime);
            }
            //查询时间超过当前时间,默认当前时间
            if (search.createdToUtc != DateTime.MinValue)
            {
                var searchtime = search.createdToUtc;
                if (search.createdToUtc > DateTime.UtcNow)
                {
                    searchtime = DateTime.UtcNow;
                }
                query = query.Where(c => c.CreatedOnUtc >= searchtime);
            }
            //是否读取推荐的栏目
            if (search.IsRecommend > 0)
            {
                query = query.Where(c => c.IsRecommend == search.IsRecommend);
            }
            //是否读取隐藏的栏目
            if (search.isShow > 0)
            {
                query = query.Where(c => c.IsShow == search.isShow);
            }
            if (!string.IsNullOrEmpty(search.parentId.ToString()))
            {
                query = query.Where(c => c.ParentId == search.parentId);
            }
            if (search.isSort)
            {
                query = query.OrderByDescending(c => c.SortIndex);
            }
            query.OrderByDescending(c => c.CreatedOnUtc);

            return(query.ToList());
        }
Exemplo n.º 2
0
        public Guid[] GetColumns(ColumnSearch search)
        {
            var query = _columnsRepository.Table;

            query = query.Where(c => (int)search.columnType == c.ColumnType);

            if (!string.IsNullOrWhiteSpace(search.columnTitle))
            {
                query = query.Where(c => c.ColumnTitle.Contains(search.columnTitle));
            }

            if (!string.IsNullOrWhiteSpace(search.columnKeys))
            {
                query = query.Where(c => c.ColumnKey.Contains(search.columnKeys));
            }

            if (search.createdFromUtc != DateTime.MinValue)
            {
                query = query.Where(c => search.createdFromUtc <= c.CreatedOnUtc);
            }

            if (search.createdFromUtc != DateTime.MinValue)
            {
                query = query.Where(c => search.createdFromUtc >= c.CreatedOnUtc);
            }

            if (!string.IsNullOrEmpty(search.parentId.ToString()))
            {
                string tree = "%," + search.parentId + ",%";
                query = query.Where(c => c.Id == search.parentId || tree.Contains(c.ColumnList));
            }


            if (search.Status != ConstKeys.IGNORE)
            {
                query = query.Where(c => (int)search.Status == c.Status);
            }

            if (search.isShow != ConstKeys.IGNORE)
            {
                query = query.Where(c => c.IsShow == search.isShow);
            }

            if (search.IsRecommend != ConstKeys.IGNORE)
            {
                query = query.Where(c => c.IsRecommend == search.IsRecommend);
            }

            if (search.isSort)
            {
                query = query.OrderByDescending(c => c.SortIndex);
            }
            else
            {
                query = query.OrderByDescending(c => c.CreatedOnUtc);
            }

            var ids = query.Select(c => c.Id).ToArray();

            return(ids);
        }