/// <summary> /// Get news listing /// </summary> /// <param name="index"></param> /// <param name="pageSize"></param> /// <param name="total"></param> /// <param name="newsType"></param> /// <param name="categoryId"></param> /// <param name="status"></param> /// <returns></returns> public NewsListingWidget GetNewsListing(int index, int pageSize, int total, NewsEnums.NewsType newsType, int?categoryId, NewsEnums.NewsStatus status = NewsEnums.NewsStatus.Active) { /* * If page size = 0, this mean we have no paging * If total = 0 then no limit * If category = 0 then no category */ var now = DateTime.UtcNow; var data = Fetch(n => n.Status == status && (!categoryId.HasValue || categoryId == 0 || n.NewsNewsCategories.Any(nc => nc.NewsCategoryId == categoryId)) && (!n.DateStart.HasValue || now >= n.DateStart) && (!n.DateEnd.HasValue || now <= n.DateEnd)); switch (newsType) { case NewsEnums.NewsType.General: data = data.Where(n => !n.IsHotNews); break; case NewsEnums.NewsType.Hot: data = data.Where(n => n.IsHotNews); break; } if (total > 0) { data = data.OrderByDescending(n => n.DateStart ?? (n.LastUpdate ?? n.Created)).Take(total); } var totalPage = 0; if (pageSize != 0) { totalPage = data.Count() / pageSize; data = data.OrderByDescending(n => n.DateStart ?? (n.LastUpdate ?? n.Created)).Skip(index * pageSize) .Take(pageSize); } var model = new NewsListingWidget { PageIndex = index, PageSize = pageSize, TotalPage = totalPage, NewsListing = data.OrderByDescending(n => n.DateStart ?? (n.LastUpdate ?? n.Created)) .ToList() .Select(n => new NewsWidget(n)) .ToList() }; return(model); }
public NewsCategoryWidget() { _newsServices = HostContainer.GetInstance <INewsService>(); NewsListing = new NewsListingWidget(); }