123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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; }
- /// <summary>
- ///
- /// </summary>
- /// <param name="expression"></param>
- /// <returns></returns>
- public Sys_User GetSingleEnableUser(System.Linq.Expressions.Expression<Func<Sys_User, bool>> expression)
- {
- System.Linq.Expressions.Expression<Func<Sys_User, bool>> 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));
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userExpression"></param>
- /// <param name="roleExpression"></param>
- /// <returns></returns>
- public IQueryable<UserView> GetUserView(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> 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;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="userExpression"></param>
- /// <param name="roleExpression"></param>
- /// <returns></returns>
- public IQueryable<StudentUserView> GetStudentUserView(Expression<Func<Sys_User, bool>> userExpression, Expression<Func<Sys_Role, bool>> 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;
- }
- }
- }
|