public ActionResult GetArticleMaterialList() { GetArticleMaterialListArgs args = RequestArgs <GetArticleMaterialListArgs>(); if (args == null) { return(RespondResult(false, "参数无效。")); } GetItemListResult <ArticleMaterialEntity> result = _materialManager.GetArticleMaterialList(UserContext.User.Domain, DomainContext.AppId, args); return(RespondDataResult(result)); }
public GetItemListResult <ArticleMaterialEntity> GetArticleMaterialList(Guid domainId, string appId, GetArticleMaterialListArgs args) { GetItemListResult <ArticleMaterialEntity> result = new GetItemListResult <ArticleMaterialEntity>(); List <AttachedWhereItem> attachedWhere = new List <AttachedWhereItem>(); attachedWhere.Add(new AttachedWhereItem("Domain", domainId)); attachedWhere.Add(new AttachedWhereItem("AppId", appId)); if (args.ExceptUnpublished) { attachedWhere.Add(new AttachedWhereItem("WeixinStatus", 2)); } SqlExpressionPagingArgs pagingArgs = new SqlExpressionPagingArgs(); pagingArgs.Page = args.Page; pagingArgs.PageSize = args.PageSize; result.ItemList = _dataBase.Select <ArticleMaterialEntity>(attachedWhere, pagingArgs); result.TotalPage = pagingArgs.TotalPage; result.Page = pagingArgs.Page; if (result.ItemList.Count == 0 && result.Page > 1) { args.Page--; return(GetArticleMaterialList(domainId, appId, args)); } else { if (result.ItemList.Count > 0) { string sql = "SELECT [Id],[ArticleMaterial],[Title],[ThumbMediaId],[ThumbUrl],[ThumbName],[Url],[Index] FROM [ArticleMaterialItem] WHERE "; List <CommandParameter> parameterList = new List <CommandParameter>(); for (int i = 0; i < result.ItemList.Count; i++) { parameterList.Add(new CommandParameter("@id" + i, result.ItemList[i].Id)); sql += " [ArticleMaterial] = @id" + i; if (i < result.ItemList.Count - 1) { sql += " OR "; } } sql += " ORDER BY [Index]"; List <ArticleMaterialItemEntity> itemList = _dataBase.Select <ArticleMaterialItemEntity>(sql, parameterList); foreach (ArticleMaterialEntity item in result.ItemList) { item.ArticleList = (from c in itemList where c.ArticleMaterial == item.Id select c).ToList(); } } return(result); } }