UserDAL.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using EMIS.Entities;
  7. using EMIS.DataLogic.Repositories;
  8. using EMIS.ViewModel;
  9. using EMIS.ViewModel.SystemView;
  10. using System.Linq.Expressions;
  11. namespace EMIS.DataLogic.SystemDAL
  12. {
  13. public class UserDAL
  14. {
  15. public UserRepository UserRepository { get; set; }
  16. public RoleRepository RoleRepository { get; set; }
  17. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  18. public LoginHistoryRepository LoginHistoryRepository { get; set; }
  19. public Sys_User GetSingleEnableUser(System.Linq.Expressions.Expression<Func<Sys_User, bool>> expression)
  20. {
  21. System.Linq.Expressions.Expression<Func<Sys_User, bool>> newExp = expression.And(u => true);
  22. return UserRepository.GetSingle(newExp,
  23. (x => x.CF_Staff.CF_College.CF_Campus.CF_University),
  24. (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University));
  25. }
  26. public IQueryable<UserView> GetUserView(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> roleExpression)
  27. {
  28. var q = (from u in UserRepository.GetList(userExpression)
  29. from ur in u.Sys_Role.DefaultIfEmpty()
  30. join r in RoleRepository.GetList(roleExpression) on ur.RoleID equals r.RoleID into dr
  31. from er in dr.DefaultIfEmpty()
  32. join dirs in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_STATUS).Name) on u.RecordStatus equals dirs.Value into ddirs
  33. from edirs in ddirs.DefaultIfEmpty()
  34. join dis in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_RoleType).Name) on ur.TypeID equals dis.Value into ddis
  35. from edis in ddis.DefaultIfEmpty()
  36. join cu in UserRepository.Entities on u.CreateUserID equals cu.UserID into dcu
  37. from ecu in dcu.DefaultIfEmpty()
  38. join mu in UserRepository.Entities on u.ModifyUserID equals mu.UserID into dmu
  39. from emu in dmu.DefaultIfEmpty()
  40. where u.CF_Staff != null
  41. select new UserView
  42. {
  43. UserID = u.UserID,
  44. LoginID = u.LoginID,
  45. Name = u.Name,
  46. DepartmentID = u.CF_Staff.DepartmentID,
  47. DepartmentCode = u.CF_Staff.CF_Department.No,
  48. DepartmentName = u.CF_Staff.CF_Department.Name,
  49. CollegeID = u.CF_Staff.CollegeID,
  50. CollegeCode = u.CF_Staff.CF_College.No,
  51. CollegeName = u.CF_Staff.CF_College.Name,
  52. BirthDate = u.CF_Staff.BirthDate,
  53. Sex = u.CF_Staff.Sex,
  54. RoleID = er.RoleID,
  55. RoleName = er.RoleName,
  56. RoleTypeName = edis.Name,//角色类型名称(教师、学生)
  57. DataRange = er.DefaultDataRange,
  58. Remarks = u.CF_Staff.Remarks,
  59. RecordStatus = u.RecordStatus,
  60. RecordStatusDesc = edirs.Name,
  61. CreateUserID = u.CreateUserID,
  62. CreateUserName = ecu.Name,
  63. CreateTime = u.CreateTime,
  64. ModifyUserID = u.ModifyUserID,
  65. ModifyUserName = emu.Name,
  66. ModifyTime = u.ModifyTime
  67. });
  68. return q;
  69. }
  70. public IQueryable<StudentUserView> GetStudentUserView(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> roleExpression)
  71. {
  72. var q = (from u in UserRepository.GetList(userExpression).Where(x => x.CF_Student.UserID != null)
  73. from ur in u.Sys_Role.DefaultIfEmpty()
  74. join r in RoleRepository.GetList(roleExpression) on ur.RoleID equals r.RoleID into dr
  75. from er in dr.DefaultIfEmpty()
  76. join dis in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_RoleType).Name) on ur.TypeID equals dis.Value into ddis
  77. from edis in ddis.DefaultIfEmpty()
  78. join dirs in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_STATUS).Name) on u.RecordStatus equals dirs.Value into ddirs
  79. from edirs in ddirs.DefaultIfEmpty()
  80. join cu in UserRepository.Entities on u.CreateUserID equals cu.UserID into dcu
  81. from ecu in dcu.DefaultIfEmpty()
  82. join mu in UserRepository.Entities on u.ModifyUserID equals mu.UserID into dmu
  83. from emu in dmu.DefaultIfEmpty()
  84. select new StudentUserView
  85. {
  86. UserID = u.UserID,
  87. LoginID = u.LoginID,
  88. Name = u.Name,
  89. Sex = u.CF_Student.Sex,
  90. IDNumber = u.CF_Student.IDNumber,
  91. BirthDate = u.CF_Student.CF_StudentProfile.BirthDate,
  92. Grade = u.CF_Student.CF_Classmajor.CF_Grademajor.SchoolyearID,
  93. ClassmajorID = u.CF_Student.ClassmajorID,
  94. ClassNo = u.CF_Student.CF_Classmajor.No,
  95. ClassmajorName = u.CF_Student.CF_Classmajor.Name,
  96. CollegeID=u.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID,
  97. InSchool = u.CF_Student.InSchoolStatusID,
  98. RoleTypeName = edis.Name,//角色类型名称(教师、学生)
  99. RoleID = er.RoleID,
  100. RoleName = er.RoleName,
  101. Remarks = u.CF_Student.CF_StudentProfile.Remarks,
  102. RecordStatus = u.RecordStatus,
  103. RecordStatusDesc = edirs.Name,
  104. CreateUserID = u.CreateUserID,
  105. CreateUserName = ecu.Name,
  106. CreateTime = u.CreateTime,
  107. ModifyUserID = u.ModifyUserID,
  108. ModifyUserName = emu.Name,
  109. ModifyTime = u.ModifyTime
  110. });
  111. return q;
  112. }
  113. }
  114. }