AnnouncementDAL.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.SystemView;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. namespace EMIS.DataLogic.SystemDAL
  10. {
  11. public class AnnouncementDAL
  12. {
  13. public AnnouncementTypeRepository AnnouncementTypeRepository { get; set; }
  14. public AnnouncementRepository AnnouncementRepository { get; set; }
  15. public UserRepository UserRepository { get; set; }
  16. public IQueryable<AnnouncementTypeView> GetAnnouncementTypeView(Expression<Func<Sys_AnnouncementType, bool>> typeExpression)
  17. {
  18. var q = (from at in AnnouncementTypeRepository.GetList(typeExpression)
  19. orderby at.No
  20. select new AnnouncementTypeView
  21. {
  22. AnnouncementTypeID = at.AnnouncementTypeID,
  23. No = at.No,
  24. Name = at.Name,
  25. Description = at.Description,
  26. RecordStatus = at.RecordStatus,
  27. CreateUserID = at.CreateUserID,
  28. CreateTime = at.CreateTime,
  29. ModifyUserID = at.ModifyUserID,
  30. ModifyTime = at.ModifyTime
  31. });
  32. return q;
  33. }
  34. public IQueryable<AnnouncementView> GetAnnouncementView(Expression<Func<Sys_Announcement, bool>> expression)
  35. {
  36. var q = (from a in AnnouncementRepository.GetList(expression)
  37. join cu in UserRepository.GetList(x => x.CF_Staff != null) on a.CreateUserID equals cu.UserID into dcu
  38. from ecu in dcu.DefaultIfEmpty()
  39. join mu in UserRepository.GetList(x => x.CF_Staff != null) on a.ModifyUserID equals mu.UserID into dmu
  40. from emu in dmu.DefaultIfEmpty()
  41. orderby a.CreateTime descending
  42. select new AnnouncementView
  43. {
  44. AnnouncementID = a.AnnouncementID,
  45. AnnouncementTypeID = a.AnnouncementTypeID,
  46. AnnouncementTypeDesc = a.Sys_AnnouncementType.Name,
  47. Title = a.Title,
  48. Content = a.Content,
  49. StartTime = a.StartTime,
  50. EndTime = a.EndTime,
  51. RecordStatus = a.RecordStatus,
  52. CreateUserID = a.CreateUserID,
  53. CreateUserName = ecu.Name,
  54. CreateTime = a.CreateTime,
  55. CreateDepartmentID = ecu.CF_Staff.DepartmentID,
  56. CreateDepartmentName = ecu.CF_Staff.CF_Department.Name,
  57. ModifyUserID = a.ModifyUserID,
  58. ModifyUserName = emu.Name,
  59. ModifyTime = a.ModifyTime
  60. });
  61. return q;
  62. }
  63. }
  64. }