RoleDAL.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using EMISOnline.DataLogic.Repositories;
  7. using EMISOnline.ViewModel.SystemView;
  8. using EMISOnline.Entities;
  9. using EMISOnline.ViewModel;
  10. namespace EMISOnline.DataLogic.SystemDAL
  11. {
  12. public class RoleDAL
  13. {
  14. public RoleRepository RoleRepository { get; set; }
  15. public StudentRoleRepository StudentRoleRepository { get; set; }
  16. public UserRepository UserRepository { get; set; }
  17. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  18. public IQueryable<RoleView> GetRoleView(Expression<Func<Sys_Role, bool>> roleExpression)
  19. {
  20. var q = (from r in RoleRepository.GetList(roleExpression)
  21. join sr in StudentRoleRepository.Entities on r.RoleID equals sr.RoleID into dsr
  22. from sr in dsr.DefaultIfEmpty()
  23. join dit in DictionaryItemRepository.Entities
  24. on new { DictionaryCode = typeof(SYS_RoleType).Name, Value = r.TypeID } equals new { dit.DictionaryCode, dit.Value }
  25. join didr in DictionaryItemRepository.Entities
  26. on new { DictionaryCode = typeof(SYS_DataRange).Name, Value = r.DefaultDataRange } equals new { didr.DictionaryCode, didr.Value } into ddidr
  27. from edidr in ddidr.DefaultIfEmpty()
  28. join dirs in DictionaryItemRepository.Entities
  29. on new { DictionaryCode = typeof(SYS_STATUS).Name, Value = r.RecordStatus } equals new { dirs.DictionaryCode, dirs.Value }
  30. join dist in DictionaryItemRepository.Entities
  31. on new { DictionaryCode = typeof(CF_STUDENTTYPE).Name, Value = sr.StudentType } equals new { dist.DictionaryCode, dist.Value } into ddist
  32. from edist in ddist.DefaultIfEmpty()
  33. join cu in UserRepository.Entities on r.CreateUserID equals cu.UserID into dcu
  34. from ecu in dcu.DefaultIfEmpty()
  35. join mu in UserRepository.Entities on r.ModifyUserID equals mu.UserID into dmu
  36. from emu in dmu.DefaultIfEmpty()
  37. orderby r.RoleName
  38. select new RoleView
  39. {
  40. RoleID = r.RoleID,
  41. TypeID = r.TypeID,
  42. TypeDesc = dit.Name,
  43. RoleName = r.RoleName,
  44. Description = r.Description,
  45. IsSystemRole = r.IsSystemRole ?? false,
  46. SystemRoleType = r.SystemRoleType,
  47. DefaultDataRange = r.DefaultDataRange,
  48. DefaultDataRangeDesc = edidr.Name,
  49. StudentType = sr.StudentType,
  50. StudentTypeDesc = edist.Name,
  51. RecordStatus = r.RecordStatus,
  52. RecordStatusDesc = dirs.Name,
  53. CreateUserID = r.CreateUserID,
  54. CreateUserName = (ecu == null) ? null : ecu.Name,
  55. CreateTime = r.CreateTime,
  56. ModifyUserID = r.ModifyUserID,
  57. ModifyUserName = (emu == null) ? null : emu.Name,
  58. ModifyTime = r.ModifyTime
  59. });
  60. return q;
  61. }
  62. }
  63. }