private NewsTypeMaterialInfoModel EntityToModel(DataRow dr)
 {
     if (dr != null)
     {
         NewsTypeMaterialInfoModel model = new NewsTypeMaterialInfoModel();
         model.MediaID          = dr["media_id"].ToString();
         model.Title            = dr["title"].ToString();
         model.ThumbMediaID     = dr["thumb_media_id"].ToString();
         model.ShowCoverPic     = dr["show_cover_pic"].ToInt();
         model.Author           = dr["author"].ToString();
         model.Digest           = dr["digest"].ToString();
         model.Content          = dr["content"].ToString();
         model.Url              = dr["url"].ToString();
         model.ContentSourceUrl = dr["content_source_url"].ToString();
         return(model);
     }
     return(null);
 }
示例#2
0
        // 自家数据库
        public List <MaterialInfoModel> GetPageList(string authorizerAppID, string type, string key, int pageIndex, int pageSize, out int totalCount)
        {
            totalCount = 0;
            try
            {
                if (type == "news")
                {
                    if (string.IsNullOrEmpty(key))
                    {
                        List <MaterialInfoModel> modelList = materialInfoDAL.GetPageList(authorizerAppID, type, pageIndex, pageSize, out totalCount);
                        if (modelList.Any())
                        {
                            foreach (var model in modelList)
                            {
                                model.NewsTypeMaterialInfoList = newsTypeMaterialInfoDAL.GetList(model.MediaID);
                            }
                        }
                        return(modelList);
                    }
                    else
                    {
                        // 搜索
                        List <NewsTypeMaterialInfoModel> newsTypeMaterialInfoList = newsTypeMaterialInfoDAL.GetList(authorizerAppID, key);
                        totalCount = newsTypeMaterialInfoList.Count;

                        List <MaterialInfoModel> modelList = new List <MaterialInfoModel>();

                        int offset  = (pageIndex - 1) * pageSize;
                        int endSize = pageIndex * pageSize;
                        if (totalCount > endSize)
                        {
                            for (int i = offset; i < endSize; i++)
                            {
                                NewsTypeMaterialInfoModel newsTypeMaterialInfoModel = newsTypeMaterialInfoList[i];
                                modelList.Add(new MaterialInfoModel()
                                {
                                    MediaID = newsTypeMaterialInfoModel.MediaID, NewsTypeMaterialInfoList = newsTypeMaterialInfoDAL.GetList(newsTypeMaterialInfoModel.MediaID),
                                });
                            }
                        }
                        else
                        {
                            for (int i = offset; i < totalCount; i++)
                            {
                                NewsTypeMaterialInfoModel newsTypeMaterialInfoModel = newsTypeMaterialInfoList[i];
                                modelList.Add(new MaterialInfoModel()
                                {
                                    MediaID = newsTypeMaterialInfoModel.MediaID, NewsTypeMaterialInfoList = newsTypeMaterialInfoDAL.GetList(newsTypeMaterialInfoModel.MediaID)
                                });
                            }
                        }
                    }
                }
                else if (type == "image")
                {
                    return(materialInfoDAL.GetPageList(authorizerAppID, type, pageIndex, pageSize, out totalCount));
                }

                return(new List <MaterialInfoModel>());
            }
            catch (Exception ex)
            {
                LogHelper.Error(ex);
                return(null);
            }
        }