RoleDAL.cs 3.2 KB

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