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; using EMIS.ViewModel.SystemManage.UserManage; namespace EMIS.DataLogic.SystemDAL { public class UserDAL { public UserRepository UserRepository { get; set; } public StaffRepository StaffRepository { get; set; } public RoleRepository RoleRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { 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 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, SexID = u.CF_Staff.SexID, BirthDate = u.CF_Staff.BirthDate, CollegeID = u.CF_Staff.CollegeID, CollegeCode = u.CF_Staff.CF_College.No, CollegeName = u.CF_Staff.CF_College.Name, DepartmentID = u.CF_Staff.DepartmentID, DepartmentCode = u.CF_Staff.CF_Department.No, DepartmentName = u.CF_Staff.CF_Department.Name, RoleOrderNo = er.OrderNo, RoleID = er.RoleID, RoleName = er.RoleName, TypeID = er.TypeID, DataRange = er.DefaultDataRange, RoleStatus = er.RecordStatus, Remark = u.CF_Staff.Remark, RecordStatus = u.RecordStatus, 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, SexID = u.CF_Student.SexID, BirthDate = u.CF_Student.BirthDate, Grade = u.CF_Student.CF_Classmajor.CF_Grademajor.GradeID, 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.Remark, 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; } } }