Exemplo n.º 1
0
        public List <NoticeReceiver> getReceiveNotice(int userId, int pagenum, int pagesize, NoticeCondition condition)
        {
            if (userId == 0)
            {
                throw new ApplicationException("用户id不能为0");
            }
            IQueryable <Notice> q = database.Notice.OrderBy(t => t.Id);

            if (condition != null)
            {
                if (condition.StartTime != null)
                {
                    q = q.Where(t => t.CreateTime >= condition.StartTime);
                }
                if (condition.EndTime != null)
                {
                    q = q.Where(t => t.CreateTime <= condition.EndTime.Value.AddDays(1));
                }
                if (!string.IsNullOrEmpty(condition.KeyWord))
                {
                    q = q.Where(t => t.Title.Contains(condition.KeyWord) || t.Content.Contains(condition.KeyWord));
                }
            }
            var m = q.Select(t => t.Id).ToList();
            List <NoticeReceiver> list = database.NoticeReceiver.Where(t => t.Receiver == userId && m.Contains(t.NoticeId)).OrderBy(t => t.Status).ThenBy(t => t.Id).Skip((pagenum - 1) * pagesize).Take(pagesize).ToList();

            if (list.Count == 0)
            {
                return(list);
            }
            foreach (NoticeReceiver item in list)
            {
                loadForeignKey(item);
            }
            return(list);
        }
Exemplo n.º 2
0
        public List <Notice> getRelease(int userId, int pagenum, int pagesize, out int count, NoticeCondition condition)
        {
            if (userId == 0)
            {
                throw new ApplicationException("用户ID不对");
            }
            IQueryable <Notice> q = defaultOrderQuery();

            if (condition != null)
            {
                if (condition.StartTime != null)
                {
                    q = q.Where(t => t.CreateTime >= condition.StartTime);
                }
                if (condition.EndTime != null)
                {
                    q = q.Where(t => t.CreateTime <= condition.EndTime.Value.AddDays(1));
                }
                if (!string.IsNullOrEmpty(condition.KeyWord))
                {
                    q = q.Where(t => t.Title.Contains(condition.KeyWord) || t.Content.Contains(condition.KeyWord));
                }
            }
            q     = q.Where(t => t.Sender == userId);
            count = q.Count();
            List <Notice> list = q.Skip((pagenum - 1) * pagesize).Take(pagesize).ToList();

            //List<Notice> list = database.Notice.Where(t => t.Sender == userId).OrderBy(t => t.Id).Skip((pagenum - 1) * pagesize).Take(pagesize).ToList();
            if (list.Count == 0)
            {
                return(list);
            }
            foreach (var item in list)
            {
                loadForeignKey(item);
            }
            return(list);
        }