using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Linq.Expressions; using EMIS.DataLogic.Repositories; using EMIS.ViewModel.SystemView; using EMIS.Entities; using EMIS.ViewModel; namespace EMIS.DataLogic.SystemDAL { public class RoleDAL { public RoleRepository RoleRepository { 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).OrderBy(c=>c.OrderNo).ThenBy(c=>c.TypeID) 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 = r.CF_StudentRole.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.OrderNo,r.TypeID select new RoleView { OrderNo = r.OrderNo, RoleID = r.RoleID, TypeID = r.TypeID, TypeDesc = dit.Name, RoleName = r.RoleName, Description = r.Description, IsSystemRole = r.IsSystemRole, SystemRoleType = r.SystemRoleType, DefaultDataRange = r.DefaultDataRange, DefaultDataRangeDesc = edidr.Name, StudentType = r.CF_StudentRole.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; } } }