public JsonResult GetList(string title, string startDate, string endDate, string newsType, int page, int rows) { int total; var newsCond = new NewsCond() { Title = title, NewsType = newsType }; if (!string.IsNullOrEmpty(startDate)) { newsCond.StartDate = Convert.ToDateTime(startDate); } if (!string.IsNullOrEmpty(endDate)) { newsCond.EndDate = Convert.ToDateTime(endDate); } var result = NewsService.Instance.GetNewsListByPage(newsCond, rows, page, out total); return(Json(new { rows = result.Select(x => new { x.Id, x.Title, x.Source, x.Content, x.Operator, x.NewsType, x.TitleImageUrl, CreateTime = x.CreateTime.ToString(), }), total }, JsonRequestBehavior.AllowGet)); }
public List <NewsDto> GetNewsListByPage(NewsCond cond, int size, int index, out int total) { var query = newsRepository.Source; if (!string.IsNullOrEmpty(cond.NewsType)) { query = query.Where(x => x.NewsType.ToString() == cond.NewsType); } if (!string.IsNullOrEmpty(cond.Title)) { query = query.Where(x => x.Title == cond.Title); } if (cond.StartDate != null && cond.EndDate != null) { query = query.Where(x => x.CreateTime >= cond.StartDate.Value && x.CreateTime <= cond.StartDate.Value); } query = query.OrderByDescending(x => x.CreateTime); return(newsRepository.FindForPaging(size, index, query, out total).ToList().ToListModel <News, NewsDto>()); }