NoticeBll.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using CP.Cache;
  2. using CP.Model;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace CP.Business
  9. {
  10. public class NoticeBll : BaseBll
  11. {
  12. /// <summary>
  13. /// 缓存
  14. /// </summary>
  15. static WMCache cache = WMCache.GetCacheService();
  16. public static List<Notice> GetNoticeList()
  17. {
  18. string key = string.Format(CacheKeys.Notice);
  19. List<Notice> list = cache.GetObject<List<Notice>>(key);
  20. if (list == null)
  21. {
  22. list = new List<Notice>();
  23. var dc = new DataConnect();
  24. string sql = string.Format(" order by addtime asc");
  25. list = dc.db.Fetch<Notice>(sql);
  26. cache.AddObject(key, list, (int)CacheTime.System);
  27. }
  28. return list;
  29. }
  30. public static List<Notice> GetNoticePage(int pageSize, int pageIndex, out int count)
  31. {
  32. var list = GetNoticeList();
  33. count = list.Count;
  34. return list == null ? new List<Notice>() : list.Skip(pageSize * (pageIndex - 1)).Take(pageSize).ToList();
  35. }
  36. public static Notice GetNotice(int id)
  37. {
  38. var list = GetNoticeList();
  39. return list == null ? new Notice() : list.Where(a => a.id == id).FirstOrDefault();
  40. }
  41. }
  42. }