コード例 #1
0
        public ResResultModel GetContentDetailList(ListModel model)
        {
            try
            {
                if (model.PageIndex < 1)
                {
                    model.PageIndex = 1;
                }
                if (model.PageSize < 1)
                {
                    model.PageSize = 10;
                }
                int totalRecord = 0;
                var bll         = new ContentDetail();

                IList <ContentDetailInfo> list = null;

                StringBuilder sqlWhere = null;
                ParamsHelper  parms    = null;
                if (!string.IsNullOrWhiteSpace(model.Keyword))
                {
                    sqlWhere = new StringBuilder(1000);
                    parms    = new ParamsHelper();
                    sqlWhere.Append("and (p.Title+p.Keyword+p.Descr) like @Keyword ");
                    parms.Add(new SqlParameter("@Keyword", "%" + model.Keyword + "%"));
                }
                var contentTypeId = Guid.Empty;
                if (model.ParentId != null && Guid.TryParse(model.ParentId.ToString(), out contentTypeId))
                {
                    list = bll.GetListByContentType(model.PageIndex, model.PageSize, out totalRecord, contentTypeId, sqlWhere == null ? null : sqlWhere.ToString(), parms == null ? null : parms.ToArray());
                }
                else
                {
                    list = bll.GetListByJoin(model.PageIndex, model.PageSize, out totalRecord, sqlWhere == null ? null : sqlWhere.ToString(), parms == null ? null : parms.ToArray());
                }

                return(ResResult.Response(true, "", "{\"total\":" + totalRecord + ",\"rows\":" + JsonConvert.SerializeObject(list) + "}"));
            }
            catch (Exception ex)
            {
                return(ResResult.Response(false, ex.Message, ""));
            }
        }