示例#1
0
        public ProInterface.Models.Api.ApiPagingDataBean BulletinList(ref ErrorInfo err, ProInterface.Models.Api.ApiRequesPageBean inEnt)
        {
            GlobalUser        gu    = Global.GetUser(inEnt.authToken);
            ApiPagingDataBean reEnt = new ApiPagingDataBean();
            int skip = 0;

            if (inEnt.currentPage > 1)
            {
                skip = (inEnt.currentPage - 1) * inEnt.pageSize;
            }
            using (DBEntities db = new DBEntities())
            {
                var tmpEnt  = db.YL_BULLETIN.AsEnumerable();
                var allData = tmpEnt.Where(x => x.IS_SHOW == 1 && x.ISSUE_DATE < DateTime.Now).OrderByDescending(x => x.IS_URGENT).ThenByDescending(x => x.ISSUE_DATE).AsEnumerable();
                allData = allData.Where(x => x.YL_ROLE.Where(y => gu.RoleID.Contains(y.ID)).Count() > 0).AsEnumerable();

                ErrorInfo error = new ErrorInfo();
                #region 过虑条件
                foreach (var filter in inEnt.searchKey)
                {
                    if (filter.K == "CREATE_TIME" && filter.T == ">=" && !string.IsNullOrEmpty(filter.V))
                    {
                        DateTime dt1 = DateTime.ParseExact(filter.V, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
                        allData = allData.Where(x => x.CREATE_TIME >= dt1).AsEnumerable();
                    }
                    else if (filter.K == "CREATE_TIME" && filter.T == "<=" && !string.IsNullOrEmpty(filter.V))
                    {
                        DateTime dt2 = DateTime.ParseExact(filter.V, "yyyy-MM-dd", System.Globalization.CultureInfo.CurrentCulture);
                        allData = allData.Where(x => x.CREATE_TIME <= dt2).AsEnumerable();
                    }
                    else if (filter.V == "全部")
                    {
                        allData = tmpEnt.Where(x => x.IS_SHOW == 1 && x.ISSUE_DATE < DateTime.Now).OrderByDescending(x => x.IS_URGENT).ThenByDescending(x => x.ISSUE_DATE).AsEnumerable();
                    }
                    else
                    {
                        allData = Fun.GetListWhere <YL_BULLETIN>(allData, filter.K, filter.T, filter.V, ref error);
                    }
                }
                #endregion
                var allList = allData.Skip(skip).Take(inEnt.pageSize).ToList();
                reEnt.currentPage = inEnt.currentPage;
                reEnt.pageSize    = inEnt.pageSize;
                reEnt.totalCount  = allData.Count();
                reEnt.totalPage   = reEnt.totalCount / reEnt.pageSize;
                if (reEnt.totalCount % reEnt.pageSize != 0)
                {
                    reEnt.totalPage++;
                }
                IList <TBulletin> reList = new List <TBulletin>();
                foreach (var t in allList)
                {
                    TBulletin tmp = Fun.ClassToCopy <YL_BULLETIN, TBulletin>(t);
                    tmp.CONTENT = Fun.NoHTML(tmp.CONTENT);
                    reList.Add(tmp);
                }
                reEnt.data = reList;
            }
            return(reEnt);
        }