// GET: New public async System.Threading.Tasks.Task <ActionResult> IndexAsync(long?CategoryCode, int?pageIndex, int?pageSize) { var result = new ResultModel(); if (CategoryCode == null || CategoryCode < 0) { result.Code = 1002; result.Message = "CategoryCode "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } if (pageIndex == null || pageIndex < 0) { result.Code = 1002; result.Message = " pageIndex "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } if (pageSize == null || pageSize < 0) { result.Code = 1002; result.Message = " pageSize "; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } try { var allC = await GetAllCategoriesByIdAsync((long)CategoryCode); var lst = repository.GetAllList((int)pageIndex, (int)pageSize, m => m.status == 0, m => m.categoryId, allC.ToArray()); EasonRepository <ArticleCategory, long> category = new EasonRepository <ArticleCategory, long>(); if (lst != null && lst.Count() > 0) { var data = Mapper.Map <IQueryable <Article>, IList <ArticleListModel> >(lst); result.Code = 0; result.Message = string.Empty; result.Data = data; result.allpageNum = repository.GetAllList(m => m.status == 0, m => m.categoryId, allC.ToArray()).Count(); result.ChildName = category.GetAll(m => m.parentId == CategoryCode); return(Jsonp(result, JsonRequestBehavior.AllowGet)); } else { result.Code = 0; result.Message = "not found"; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { result.Code = 1001; result.Message = ex.Message; return(Jsonp(result, JsonRequestBehavior.AllowGet)); } }
public ActionResult List(int offset, int limit, string search) { IQueryable <InfoBanner> articles; if (string.IsNullOrEmpty(search)) { articles = repository.GetAllList(offset, limit); } else { articles = repository.GetAllList(offset, limit, m => m.title.Contains(search)); } var total = repository.Count(); return(Jsonp(new { total = total, rows = articles }, JsonRequestBehavior.AllowGet)); } // GET: Users/Details/5
public ActionResult List(int offset, int limit, string search) { IQueryable <TotalMessage> articles; if (string.IsNullOrEmpty(search)) { articles = repository.GetAllList(offset, limit); } else { articles = repository.GetAllList(offset, limit, m => m.remark.Contains(search)); } var total = repository.Count(); return(Jsonp(new { total = total, rows = articles }, JsonRequestBehavior.AllowGet)); }
public ActionResult List(int offset, int limit, string search, long?id) { if (id == null) { return(Jsonp(new { total = 0, rows = 0 }, JsonRequestBehavior.AllowGet)); } IQueryable <ArticleComment> articles; if (string.IsNullOrEmpty(search)) { articles = repository.GetAllList(offset, limit, m => m.articleId == id); } else { articles = repository.GetAllList(offset, limit, m => (m.contents.Contains(search) || m.creatorName.Contains(search)) && m.articleId == id); } var total = repository.Count(); return(Jsonp(new { total = total, rows = articles }, JsonRequestBehavior.AllowGet)); }
public async Task <JsonpResult> List(int offset, int limit, string search, long categoryid) { IQueryable <Article> articles; var total = 0; if (string.IsNullOrEmpty(search)) { if (categoryid != 0L) { var allC = await GetAllCategoriesByIdAsync(categoryid); articles = repository.GetAllList(offset, limit, m => m.categoryId, allC.ToArray()); total = repository.Count(m => m.categoryId, allC.ToArray()); } else { articles = repository.GetAllList(offset, limit); total = repository.Count(); } } else { if (categoryid != 0L) { var allC = await GetAllCategoriesByIdAsync(categoryid); articles = repository.GetAllList(offset, limit, m => m.title.Contains(search) || m.creatorName.Contains(search), m => m.categoryId, allC.ToArray()); total = repository.Count(m => m.title.Contains(search) || m.creatorName.Contains(search), m => m.categoryId, allC.ToArray()); } else { articles = repository.GetAllList(offset, limit, m => m.title.Contains(search) || m.creatorName.Contains(search)); total = repository.Count(m => m.title.Contains(search) || m.creatorName.Contains(search)); } } //var result = Mapper.Map<IQueryable<User>, IList<UserDto>>(users); return(Jsonp(new { total = total, rows = articles }, JsonRequestBehavior.AllowGet)); }
public JsonpResult List(int offset, int limit, string search) { IList <ArticleCategory> oldList; if (string.IsNullOrEmpty(search)) { oldList = easonRepository.GetAllList(offset, limit).ToList(); } else { oldList = easonRepository.GetAllList(offset, limit, m => m.title.Contains(search)).ToList(); } //原始根 var roots = oldList.Where(i => i.parentId == 0); //获取所有父亲 var parents = oldList.GroupBy(m => m.parentId).Select(x => x.FirstOrDefault()).Where(i => i.parentId != 0).OrderBy(m => m.id).ToList(); var newList = new List <ArticleCategory>(); foreach (var item in roots) { parents.Add(item); // newList.Add(item); } parents = parents.OrderBy(m => m.parentId).ToList(); for (int i = 0; i < parents.Count(); i++) { if (!newList.Contains(parents[i])) { newList.Add(parents[i]); GetChild(parents[i].id, oldList, newList); } } var total = easonRepository.Count(); return(Jsonp(new { total = total, rows = newList }, JsonRequestBehavior.AllowGet)); }