using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using EMIS.Entities; using EMIS.DataLogic.Repositories; using EMIS.ViewModel; using EMIS.ViewModel.SystemView; using System.Linq.Expressions; namespace EMIS.DataLogic.SystemDAL { public class UserDAL { public UserRepository UserRepository { get; set; } public RoleRepository RoleRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } public LoginHistoryRepository LoginHistoryRepository { get; set; } public Sys_User GetSingleEnableUser(System.Linq.Expressions.Expression> expression) { System.Linq.Expressions.Expression> newExp = expression.And(u => true); return UserRepository.GetSingle(newExp, (x => x.CF_Staff.CF_College.CF_Campus.CF_University), (x => x.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CF_College.CF_Campus.CF_University)); } public IQueryable GetUserView(Expression> userExpression, Expression> roleExpression) { var q = (from u in UserRepository.GetList(userExpression) from ur in u.Sys_Role.DefaultIfEmpty() join r in RoleRepository.GetList(roleExpression) on ur.RoleID equals r.RoleID into dr from er in dr.DefaultIfEmpty() join dirs in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_STATUS).Name) on u.RecordStatus equals dirs.Value into ddirs from edirs in ddirs.DefaultIfEmpty() join dis in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_RoleType).Name) on ur.TypeID equals dis.Value into ddis from edis in ddis.DefaultIfEmpty() join cu in UserRepository.Entities on u.CreateUserID equals cu.UserID into dcu from ecu in dcu.DefaultIfEmpty() join mu in UserRepository.Entities on u.ModifyUserID equals mu.UserID into dmu from emu in dmu.DefaultIfEmpty() where u.CF_Staff != null select new UserView { UserID = u.UserID, LoginID = u.LoginID, Name = u.Name, DepartmentID = u.CF_Staff.DepartmentID, DepartmentCode = u.CF_Staff.CF_Department.No, DepartmentName = u.CF_Staff.CF_Department.Name, CollegeID = u.CF_Staff.CollegeID, CollegeCode = u.CF_Staff.CF_College.No, CollegeName = u.CF_Staff.CF_College.Name, BirthDate = u.CF_Staff.BirthDate, Sex = u.CF_Staff.Sex, RoleID = er.RoleID, RoleName = er.RoleName, RoleTypeName = edis.Name,//角色类型名称(教师、学生) DataRange = er.DefaultDataRange, Remarks = u.CF_Staff.Remarks, RecordStatus = u.RecordStatus, RecordStatusDesc = edirs.Name, CreateUserID = u.CreateUserID, CreateUserName = ecu.Name, CreateTime = u.CreateTime, ModifyUserID = u.ModifyUserID, ModifyUserName = emu.Name, ModifyTime = u.ModifyTime }); return q; } public IQueryable GetStudentUserView(Expression> userExpression, Expression> roleExpression) { var q = (from u in UserRepository.GetList(userExpression).Where(x => x.CF_Student.UserID != null) from ur in u.Sys_Role.DefaultIfEmpty() join r in RoleRepository.GetList(roleExpression) on ur.RoleID equals r.RoleID into dr from er in dr.DefaultIfEmpty() join dis in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_RoleType).Name) on ur.TypeID equals dis.Value into ddis from edis in ddis.DefaultIfEmpty() join dirs in DictionaryItemRepository.GetList(x => x.DictionaryCode == typeof(SYS_STATUS).Name) on u.RecordStatus equals dirs.Value into ddirs from edirs in ddirs.DefaultIfEmpty() join cu in UserRepository.Entities on u.CreateUserID equals cu.UserID into dcu from ecu in dcu.DefaultIfEmpty() join mu in UserRepository.Entities on u.ModifyUserID equals mu.UserID into dmu from emu in dmu.DefaultIfEmpty() select new StudentUserView { UserID = u.UserID, LoginID = u.LoginID, Name = u.Name, Sex = u.CF_Student.Sex, IDNumber = u.CF_Student.IDNumber, BirthDate = u.CF_Student.CF_StudentProfile.BirthDate, Grade = u.CF_Student.CF_Classmajor.CF_Grademajor.SchoolyearID, ClassmajorID = u.CF_Student.ClassmajorID, ClassNo = u.CF_Student.CF_Classmajor.No, ClassmajorName = u.CF_Student.CF_Classmajor.Name, CollegeID=u.CF_Student.CF_Classmajor.CF_Grademajor.CF_Facultymajor.CollegeID, InSchool = u.CF_Student.InSchoolStatusID, RoleTypeName = edis.Name,//角色类型名称(教师、学生) RoleID = er.RoleID, RoleName = er.RoleName, Remarks = u.CF_Student.CF_StudentProfile.Remarks, RecordStatus = u.RecordStatus, RecordStatusDesc = edirs.Name, CreateUserID = u.CreateUserID, CreateUserName = ecu.Name, CreateTime = u.CreateTime, ModifyUserID = u.ModifyUserID, ModifyUserName = emu.Name, ModifyTime = u.ModifyTime }); return q; } } }