RoleDAL.cs 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. //orderby r.OrderNo,r.TypeID
  35. select new RoleView
  36. {
  37. OrderNo = r.OrderNo,
  38. RoleID = r.RoleID,
  39. TypeID = r.TypeID,
  40. TypeDesc = dit.Name,
  41. RoleName = r.RoleName,
  42. Description = r.Description,
  43. IsSystemRole = r.IsSystemRole,
  44. SystemRoleType = r.SystemRoleType,
  45. DefaultDataRange = r.DefaultDataRange,
  46. DefaultDataRangeDesc = edidr.Name,
  47. StudentType = r.CF_StudentRole.StudentType,
  48. StudentTypeDesc = edist.Name,
  49. RecordStatus = r.RecordStatus,
  50. RecordStatusDesc = dirs.Name,
  51. CreateUserID = r.CreateUserID,
  52. CreateUserName = (ecu == null) ? null : ecu.Name,
  53. CreateTime = r.CreateTime,
  54. ModifyUserID = r.ModifyUserID,
  55. ModifyUserName = (emu == null) ? null : emu.Name,
  56. ModifyTime = r.ModifyTime
  57. });
  58. return q;
  59. }
  60. }
  61. }