Exemplo n.º 1
0
        /// <summary>
        /// 分页查询新闻公告
        /// </summary>
        /// <param name="filter"></param>
        /// <param name="totalCount"></param>
        /// <returns></returns>
        public static QueryResult <NewsInfo> QueryNewsInfo(NewsQueryFilter filter)
        {
            CustomDataCommand command = DataCommandManager.CreateCustomDataCommandFromConfig("Content_QueryTopic");

            using (DynamicQuerySqlBuilder sqlBuilder = new DynamicQuerySqlBuilder(command.CommandText, command, filter.ConvertToPaging(), "TopMost DESC,SysNo DESC"))
            {
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "SysNo", DbType.Int32, "@SysNo", QueryConditionOperatorType.Equal, filter.SysNo);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "Status", DbType.Int32, "@Status", QueryConditionOperatorType.Equal, 1);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "ReferenceSysNo", DbType.Int32, "@ReferenceSysNo", QueryConditionOperatorType.Equal, filter.ReferenceSysNo);
                if (filter.NewsType.HasValue)
                {
                    sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "NewsType", DbType.Int32, "@NewsType", QueryConditionOperatorType.Equal, (int)filter.NewsType.Value);
                }
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "PageShowInheritance", DbType.Int32, "@PageShowInheritance", QueryConditionOperatorType.Equal, filter.PageShowInheritance);
                sqlBuilder.ConditionConstructor.AddCondition(QueryConditionRelationType.AND, "ExpireDate", DbType.Time, "@ExpireDateBegin", QueryConditionOperatorType.MoreThan, DateTime.Now);
                command.CommandText = sqlBuilder.BuildQuerySql();
                var newsList   = command.ExecuteEntityList <NewsInfo>();
                var totalCount = Convert.ToInt32(command.GetParameterValue("@TotalCount"));

                QueryResult <NewsInfo> result = new QueryResult <NewsInfo>();
                result.ResultList = newsList;
                result.PageInfo   = filter.ConvertToPageInfo(totalCount);
                return(result);
            }
        }
Exemplo n.º 2
0
        public static QueryResult <NewsInfoViewModel> GetNewsList(int pageIndex, int pageSize)
        {
            NewsQueryFilter queryFilter = new NewsQueryFilter()
            {
                PageInfo = new PageInfo()
                {
                    PageIndex = pageIndex + 1, PageSize = pageSize
                }, NewsType = NewsType.HomePageNews
            };

            return(EntityConverter <QueryResult <NewsInfo>, QueryResult <NewsInfoViewModel> > .Convert(TopicFacade.QueryNewsInfo(queryFilter), (s, t) =>
            {
                for (int i = 0; i < s.ResultList.Count; i++)
                {
                    t.ResultList[i].CreateTimeString = s.ResultList[i].CreateDate.ToString("yyyy-MM-dd");
                    t.ResultList[i].Title = StringUtility.RemoveHtmlTag(t.ResultList[i].Title);
                    string rawHtmlContent = t.ResultList[i].Content;
                    if (!string.IsNullOrEmpty(rawHtmlContent))
                    {
                        string plainTextContent = StringUtility.RemoveHtmlTag(rawHtmlContent).Replace("&nbsp;", "");
                        t.ResultList[i].Content = (plainTextContent.Length > 60 ? plainTextContent.Substring(0, 60) + "..." : plainTextContent);
                        t.ResultList[i].ImageUrl = ExtractImageSrc(rawHtmlContent);
                    }
                }
            }));
        }
Exemplo n.º 3
0
        public ActionResult Ajax_QueryNews()
        {
            NewsQueryFilter query = new NewsQueryFilter();

            query.PageInfo           = new PageInfo();
            query.PageInfo.PageSize  = 5;
            query.PageInfo.PageIndex = 1;
            //新闻类型
            //query.ReferenceSysNo = Model;

            string strPageIndex = Request["page"];

            if (!string.IsNullOrWhiteSpace(strPageIndex))
            {
                int pageIndex = 1;
                int.TryParse(strPageIndex, out pageIndex);
                query.PageInfo.PageIndex = pageIndex;
            }
            ViewDataDictionary     dic      = new ViewDataDictionary();
            QueryResult <NewsInfo> newsList = TopicFacade.QueryNewsInfo(query);

            var result = new AjaxResult {
                Success = true
            };

            result.Data = newsList;

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 4
0
        private static IEnumerable <string> BuildTopic()
        {
            var urlTemp = Path.Combine(Domain, "Topic/TopicDetail/{0}");
            var result  = new List <string>();

            var filter = new NewsQueryFilter
            {
                PageInfo = new PageInfo
                {
                    PageIndex = 1,
                    PageSize  = 10000
                }
            };

            var news = TopicDA.QueryNewsInfo(filter);

            foreach (NewsInfo item in news.ResultList)
            {
                result.Add(string.Format(urlTemp, item.SysNo));
            }

            return(result);
        }
Exemplo n.º 5
0
 /// <summary>
 /// 分页查询新闻公告
 /// </summary>
 /// <param name="filter"></param>
 /// <param name="totalCount"></param>
 /// <returns></returns>
 public static QueryResult <NewsInfo> QueryNewsInfo(NewsQueryFilter filter)
 {
     return(TopicDA.QueryNewsInfo(filter));
 }
Exemplo n.º 6
0
        /// <summary>
        /// Xem danh sách tin tức theo filter: title, content, ...
        /// Phân trang
        /// </summary>
        /// <param name="filter"></param>
        /// <returns></returns>
        public async Task <PaginatedList <NewsResponse> > GetNewsByFilterAsync(NewsQueryFilter filter)
        {
            var dataResponse = new List <NewsResponse>();

            foreach (var item in _newsContext.News)
            {
                dataResponse.Add(new NewsResponse
                {
                    Id         = item.Id,
                    Title      = item.Title,
                    Content    = item.Content,
                    CreateTime = item.CreateTime,
                    UpdateTime = item.UpdateTime,
                    Categories = await GetCategoryModels(item.Id),
                    UrlImage   = item.UrlImage
                });
            }

            if (filter.CategoryIds != null && filter.CategoryIds.Count() > 0)
            {
                var filterMenuByCategory = new List <Guid>();
                foreach (var id in filter.CategoryIds)
                {
                    var newsCate = _newsContext.CategoryNews.Where(x => x.CategoryId.Equals(id)).Select(y => y.NewsId);
                    filterMenuByCategory.AddRange(newsCate);
                }

                var listIndexMenuRemove = new List <int>();
                int i = 0;
                foreach (var item in dataResponse)
                {
                    if (!filterMenuByCategory.Exists(x => item.Id.Equals(x)))
                    {
                        listIndexMenuRemove.Add(i);
                    }
                    ;
                    i++;
                }
                for (int j = listIndexMenuRemove.Count(); j >= 0; j--)
                {
                    dataResponse.RemoveAt(j);
                }
            }

            if (!string.IsNullOrEmpty(filter.Title))
            {
                dataResponse = dataResponse.Where(x => x.Title.Contains(filter.Title)).ToList();
            }

            if (!string.IsNullOrEmpty(filter.Content))
            {
                dataResponse = dataResponse.Where(x => x.Content.Contains(filter.Content)).ToList();
            }

            if (!filter.PageSize.HasValue && !filter.PageNumber.HasValue)
            {
                return(await PaginatedList <NewsResponse> .CreateAsync(dataResponse));
            }

            return(await PaginatedList <NewsResponse> .CreateAsync(dataResponse, filter.PageNumber.Value, filter.PageSize.Value));
        }