using System; using System.Collections.Generic; using System.Linq; using System.Text; using Bowin.Common.Linq; using EMISOnline.Entities; using EMISOnline.DataLogic.Repositories; using EMISOnline.ViewModel; using EMISOnline.ViewModel.SystemView; using System.Linq.Expressions; namespace EMISOnline.DataLogic.SystemDAL { public class UserDAL { public UserRepository UserRepository { get; set; } public User_Sys_RoleRepository User_Sys_RoleRepository { get; set; } public RoleRepository RoleRepository { get; set; } public CampusRepository CampusRepository { get; set; } public CollegeRepository CollegeRepository { get; set; } public DepartmentRepository DepartmentRepository { get; set; } public StaffRepository StaffRepository { get; set; } public StudentRepository StudentRepository { get; set; } public DictionaryItemRepository DictionaryItemRepository { get; set; } public Sys_User GetSingleEnableUser(System.Linq.Expressions.Expression> expression) { System.Linq.Expressions.Expression> newExp = expression.And(u => u.RecordStatus == (int)SYS_STATUS.USABLE); return UserRepository.GetSingle(newExp); } public IQueryable GetUserView(Expression> userExpression, Expression> roleExpression) { var q = (from u in UserRepository.GetList(userExpression) join ur in User_Sys_RoleRepository.Entities on u.UserID equals ur.UserID into dur from ur in dur.DefaultIfEmpty() join r in RoleRepository.Entities on ur.RoleID equals r.RoleID into dr from er in dr.DefaultIfEmpty() join s in StaffRepository.Entities on u.UserID equals s.UserID into ds from es in ds.DefaultIfEmpty() join stu in StudentRepository.Entities on u.UserID equals stu.UserID into dstu from estu in dstu.DefaultIfEmpty() join d in DepartmentRepository.Entities on es.DepartmentID equals d.DepartmentID into dd from ed in dd.DefaultIfEmpty() join c in CollegeRepository.Entities on es.CollegeID equals c.CollegeID into dc from ec in dc.DefaultIfEmpty() join cp in CampusRepository.Entities on ec.CampusID equals cp.CampusID into dcp from ecp in dcp.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 UserView { UserID = u.UserID, LoginID = u.LoginID, Name = u.Name, UniversityID = ecp.UniversityID, CampusID = ec.CampusID, CollegeID = ec.CollegeID, CollegeName = ec.Name, DepartmentID = es.DepartmentID, DepartmentName = ed.Name, HierarchyID = ed.HierarchyID, StaffID = es.UserID, StudentID = estu.UserID, BirthDate = es.BirthDate, Sex = es.Sex, RoleID = er.RoleID, RoleName = er.RoleName, DataRange = er.DefaultDataRange, Remarks = es.Remarks, 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 GetUserRoles(Expression> userExpression, Expression> roleExpression) { var q = (from u in UserRepository.GetList(userExpression) join ur in User_Sys_RoleRepository.Entities on u.UserID equals ur.UserID join r in RoleRepository.Entities on ur.RoleID equals r.RoleID select r); return q; } } }