UserDAL.cs 4.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Bowin.Common.Linq;
  6. using EMISOnline.Entities;
  7. using EMISOnline.DataLogic.Repositories;
  8. using EMISOnline.ViewModel;
  9. using EMISOnline.ViewModel.SystemView;
  10. using System.Linq.Expressions;
  11. namespace EMISOnline.DataLogic.SystemDAL
  12. {
  13. public class UserDAL
  14. {
  15. public UserRepository UserRepository { get; set; }
  16. public User_Sys_RoleRepository User_Sys_RoleRepository { get; set; }
  17. public RoleRepository RoleRepository { get; set; }
  18. public CampusRepository CampusRepository { get; set; }
  19. public CollegeRepository CollegeRepository { get; set; }
  20. public DepartmentRepository DepartmentRepository { get; set; }
  21. public StaffRepository StaffRepository { get; set; }
  22. public StudentRepository StudentRepository { get; set; }
  23. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  24. public Sys_User GetSingleEnableUser(System.Linq.Expressions.Expression<Func<Sys_User, bool>> expression)
  25. {
  26. System.Linq.Expressions.Expression<Func<Sys_User, bool>> newExp = expression.And(u => u.RecordStatus == (int)SYS_STATUS.USABLE);
  27. return UserRepository.GetSingle(newExp);
  28. }
  29. public IQueryable<UserView> GetUserView(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> roleExpression)
  30. {
  31. var q = (from u in UserRepository.GetList(userExpression)
  32. join ur in User_Sys_RoleRepository.Entities on u.UserID equals ur.UserID into dur
  33. from ur in dur.DefaultIfEmpty()
  34. join r in RoleRepository.Entities on ur.RoleID equals r.RoleID into dr
  35. from er in dr.DefaultIfEmpty()
  36. join s in StaffRepository.Entities on u.UserID equals s.UserID into ds
  37. from es in ds.DefaultIfEmpty()
  38. join stu in StudentRepository.Entities on u.UserID equals stu.UserID into dstu
  39. from estu in dstu.DefaultIfEmpty()
  40. join d in DepartmentRepository.Entities on es.DepartmentID equals d.DepartmentID into dd
  41. from ed in dd.DefaultIfEmpty()
  42. join c in CollegeRepository.Entities on es.CollegeID equals c.CollegeID into dc
  43. from ec in dc.DefaultIfEmpty()
  44. join cp in CampusRepository.Entities on ec.CampusID equals cp.CampusID into dcp
  45. from ecp in dcp.DefaultIfEmpty()
  46. join cu in UserRepository.Entities on u.CreateUserID equals cu.UserID into dcu
  47. from ecu in dcu.DefaultIfEmpty()
  48. join mu in UserRepository.Entities on u.ModifyUserID equals mu.UserID into dmu
  49. from emu in dmu.DefaultIfEmpty()
  50. select new UserView
  51. {
  52. UserID = u.UserID,
  53. LoginID = u.LoginID,
  54. Name = u.Name,
  55. UniversityID = ecp.UniversityID,
  56. CampusID = ec.CampusID,
  57. CollegeID = ec.CollegeID,
  58. CollegeName = ec.Name,
  59. DepartmentID = es.DepartmentID,
  60. DepartmentName = ed.Name,
  61. HierarchyID = ed.HierarchyID,
  62. StaffID = es.UserID,
  63. StudentID = estu.UserID,
  64. BirthDate = es.BirthDate,
  65. Sex = es.Sex,
  66. RoleID = er.RoleID,
  67. RoleName = er.RoleName,
  68. DataRange = er.DefaultDataRange,
  69. Remarks = es.Remarks,
  70. RecordStatus = u.RecordStatus,
  71. CreateUserID = u.CreateUserID,
  72. CreateUserName = ecu.Name,
  73. CreateTime = u.CreateTime,
  74. ModifyUserID = u.ModifyUserID,
  75. ModifyUserName = emu.Name,
  76. ModifyTime = u.ModifyTime
  77. });
  78. return q;
  79. }
  80. public IQueryable<Sys_Role> GetUserRoles(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> roleExpression)
  81. {
  82. var q = (from u in UserRepository.GetList(userExpression)
  83. join ur in User_Sys_RoleRepository.Entities on u.UserID equals ur.UserID
  84. join r in RoleRepository.Entities on ur.RoleID equals r.RoleID
  85. select r);
  86. return q;
  87. }
  88. }
  89. }