using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using EMISOnline.DataLogic.Repositories; using EMISOnline.ViewModel.SystemView; using EMISOnline.Entities; using EMISOnline.ViewModel; namespace EMISOnline.DataLogic.SystemDAL { public class RoleDAL { public RoleRepository RoleRepository { get; set; } public StudentRoleRepository StudentRoleRepository { get; set; } public UserRepository UserRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } public IQueryable GetRoleView(Expression> roleExpression) { var q = (from r in RoleRepository.GetList(roleExpression) join sr in StudentRoleRepository.Entities on r.RoleID equals sr.RoleID into dsr from sr in dsr.DefaultIfEmpty() join dit in DictionaryItemRepository.Entities on new { DictionaryCode = typeof(SYS_RoleType).Name, Value = r.TypeID } equals new { dit.DictionaryCode, dit.Value } join didr in DictionaryItemRepository.Entities on new { DictionaryCode = typeof(SYS_DataRange).Name, Value = r.DefaultDataRange } equals new { didr.DictionaryCode, didr.Value } into ddidr from edidr in ddidr.DefaultIfEmpty() join dirs in DictionaryItemRepository.Entities on new { DictionaryCode = typeof(SYS_STATUS).Name, Value = r.RecordStatus } equals new { dirs.DictionaryCode, dirs.Value } join dist in DictionaryItemRepository.Entities on new { DictionaryCode = typeof(CF_STUDENTTYPE).Name, Value = sr.StudentType } equals new { dist.DictionaryCode, dist.Value } into ddist from edist in ddist.DefaultIfEmpty() join cu in UserRepository.Entities on r.CreateUserID equals cu.UserID into dcu from ecu in dcu.DefaultIfEmpty() join mu in UserRepository.Entities on r.ModifyUserID equals mu.UserID into dmu from emu in dmu.DefaultIfEmpty() orderby r.RoleName select new RoleView { RoleID = r.RoleID, TypeID = r.TypeID, TypeDesc = dit.Name, RoleName = r.RoleName, Description = r.Description, IsSystemRole = r.IsSystemRole ?? false, SystemRoleType = r.SystemRoleType, DefaultDataRange = r.DefaultDataRange, DefaultDataRangeDesc = edidr.Name, StudentType = sr.StudentType, StudentTypeDesc = edist.Name, RecordStatus = r.RecordStatus, RecordStatusDesc = dirs.Name, CreateUserID = r.CreateUserID, CreateUserName = (ecu == null) ? null : ecu.Name, CreateTime = r.CreateTime, ModifyUserID = r.ModifyUserID, ModifyUserName = (emu == null) ? null : emu.Name, ModifyTime = r.ModifyTime }); return q; } } }