123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Web;
- using Autofac;
- using Bowin.Common;
- using EMIS.Entities;
- using System.Linq.Expressions;
- using System.Data.Entity;
- using EMIS.DataLogic.Common;
- using Bowin.Common.Linq.Entity;
- using EMIS.DataLogic.Common.AdministrativeOrgan;
- using EMIS.ViewModel;
- using EMIS.DataLogic.SystemDAL;
- using EMIS.Utility.FormValidate;
- using EMIS.Utility;
- namespace EMIS.CommonLogic
- {
- public class BaseServices : IBaseServices
- {
- public EMIS.DataLogic.UnitOfWork UnitOfWork { get; set; }
- public EMIS.DataLogic.HRUnitOfWork HRUnitOfWork { get; set; }
- public EMIS.DataLogic.LogUnitOfWork LogUnitOfWork { get; set; }
- private DataRangeDAL DataRangeDAL { get; set; }
- public BaseServices()
- {
- DataRangeDAL = AutofacHelper.RequestLifetimeScope.Resolve<DataRangeDAL>();
- }
- protected Expression<Func<T, bool>> GetDataRageExpression<T>(Expression<Func<T, Guid?>> userColumn)
- {
- ParameterExpression paramter;
- var userColumnExp = userColumn;
- paramter = userColumnExp.Parameters[0];
- SYS_DataRange dataRange;
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- if (curUser.IsStudent)
- {
- dataRange = SYS_DataRange.Teacher;
- }
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
- IQueryable<Guid?> userIDQueryable;
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return (x => true);
- case SYS_DataRange.Campus:
- userIDQueryable = UnitOfWork.CF_StaffManageCampus.Where(x => x.UserID == curUserID)
- .SelectMany(x => x.CF_Campus.CF_College).SelectMany(x => x.CF_Staff).Select(x => (Guid?)x.UserID);
- break;
- case SYS_DataRange.College:
- userIDQueryable = UnitOfWork.CF_StaffManageCollege.Where(x => x.UserID == curUserID)
- .SelectMany(x => x.CF_College.CF_Staff).Select(x => (Guid?)x.UserID);
- break;
- case SYS_DataRange.Department:
- userIDQueryable = UnitOfWork.CF_StaffManageDepartment.Where(x => x.UserID == curUserID)
- .SelectMany(x => x.CF_Department.CF_Staff).Select(x => (Guid?)x.UserID);
- break;
- case SYS_DataRange.Assistant:
- return (x => false);
- case SYS_DataRange.Teacher:
- return Expression.Lambda<Func<T, bool>>(Expression.Equal(userColumnExp.Body, Expression.Constant(curUserID, typeof(Guid?))), paramter);
- }
- return Expression.Lambda<Func<T, bool>>(Expression.Call(typeof(Queryable), "Contains", new Type[] { typeof(Guid?) }, userIDQueryable.Expression, userColumnExp.Body), paramter);
- }
- protected Expression<Func<T, bool>> GetDataRageExpressionByCollege<T>(Expression<Func<T, Guid?>> collegeColumn)
- {
- ParameterExpression paramter;
- var collegeColumnExp = collegeColumn;
- paramter = collegeColumnExp.Parameters[0];
- SYS_DataRange dataRange;
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- if (curUser.IsStudent)
- {
- dataRange = SYS_DataRange.Teacher;
- }
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
- IQueryable<Guid?> collegeIDQueryable;
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return (x => true);
- case SYS_DataRange.Campus:
- collegeIDQueryable = UnitOfWork.CF_StaffManageCampus.Where(x => x.UserID == curUserID)
- .SelectMany(x => x.CF_Campus.CF_College).Select(x => (Guid?)x.CollegeID);
- break;
- case SYS_DataRange.College:
- collegeIDQueryable = UnitOfWork.CF_StaffManageCollege.Where(x => x.UserID == curUserID)
- .Select(x => (Guid?)x.CollegeID);
- break;
- case SYS_DataRange.Department:
- collegeIDQueryable = UnitOfWork.CF_StaffManageDepartment.Where(x => x.UserID == curUserID)
- .Select(x => (Guid?)x.CF_Department.CollegeID);
- break;
- case SYS_DataRange.Assistant:
- return (x => false);
- case SYS_DataRange.Teacher:
- return Expression.Lambda<Func<T, bool>>(Expression.Equal(collegeColumnExp.Body, Expression.Constant(curUser.CollegeID, typeof(Guid?))), paramter);
- }
- return Expression.Lambda<Func<T, bool>>(Expression.Call(typeof(Queryable), "Contains", new Type[] { typeof(Guid?) }, collegeIDQueryable.Expression, collegeColumnExp.Body), paramter);
- }
- protected IQueryable<T> GetQueryByAssistant<T>(IQueryable<T> query, Expression<Func<T, Guid?>> classmajorColumn = null, IQueryable<T> defaultQuery = null)
- {
- ExpressionFactory<T> factory = new ExpressionFactory<T>(query);
- var outerExp = classmajorColumn;
- if (classmajorColumn == null)
- {
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "ClassmajorID"), typeof(Guid?)), paramter);
- }
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- if (curUser.IsStudent)
- {
- return query;
- }
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
- if (dataRange == SYS_DataRange.Assistant)
- {
- var queryWithClassmajor = query.Join(
- UnitOfWork.CF_Classmajor.AsQueryable().Where(x => x.UserID == curUserID),
- outerExp,
- (x => x.ClassmajorID),
- ((x, y) => x));
- return queryWithClassmajor;
- }
- else
- {
- if (defaultQuery != null)
- {
- return defaultQuery;
- }
- else
- {
- return query;
- }
- }
- }
- protected IQueryable<T> GetQueryByDataRange<T>(IQueryable<T> query, Expression<Func<T, Guid?>> userColumn = null)
- {
- ExpressionFactory<T> factory = new ExpressionFactory<T>(query);
- var outerExp = userColumn;
- if (userColumn == null)
- {
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Property(paramter, "CreateUserID"), paramter);
- }
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- if (curUser.IsStudent)
- {
- return query;
- }
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
- var queryWithUserAndDepartment = query
- .Join(UnitOfWork.CF_Staff.AsQueryable(), outerExp, (x => x.UserID), ((x, y) => new { result = x, user = y }));
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return query;
- case SYS_DataRange.Campus:
- return query
- .Join(
- UnitOfWork.CF_Campus.SelectMany(x => x.CF_StaffManageCampus)
- .Where(x => x.UserID == curUser.UserID)
- .SelectMany(x => x.CF_Campus.CF_College.SelectMany(w => w.CF_Staff)),
- outerExp, (x => x.UserID), ((x, y) => x));
- case SYS_DataRange.College:
- return query
- .Join(
- UnitOfWork.CF_College.SelectMany(x => x.CF_StaffManageCollege)
- .Where(x => x.UserID == curUser.UserID)
- .SelectMany(x => x.CF_College.CF_Staff),
- outerExp, (x => x.UserID), ((x, y) => x));
- case SYS_DataRange.Department:
- return query
- .Join(
- UnitOfWork.CF_Department.SelectMany(x => x.CF_StaffManageDepartment)
- .Where(x => x.UserID == curUser.UserID)
- .SelectMany(x => x.CF_Department.CF_Staff),
- outerExp, (x => x.UserID), ((x, y) => x));
- case SYS_DataRange.Assistant:
- return query.Where(x => false);
- case SYS_DataRange.Teacher:
- return query
- .Join(
- UnitOfWork.CF_Staff.Where(x => x.UserID == curUser.UserID),
- outerExp, (x => x.UserID), ((x, y) => x));
- }
- }
- protected IQueryable<T> GetQueryByDataRangeByCampus<T>(IQueryable<T> query, Expression<Func<T, Guid?>> campusColumn = null)
- {
- ExpressionFactory<T> factory = new ExpressionFactory<T>(query);
- var outerExp = campusColumn;
- if (campusColumn == null)
- {
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "CampusID"), typeof(Guid?)), paramter);
- }
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- if (curUser.IsStudent)
- {
- return query;
- }
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
- var queryWithCampus = query
- .Join(UnitOfWork.CF_Campus.AsQueryable(), outerExp, (x => x.CampusID), ((x, y) => new { result = x, campus = y }));
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return query;
- case SYS_DataRange.Campus:
- return queryWithCampus
- .Where(x => x.campus.CF_StaffManageCampus.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.College:
- return queryWithCampus
- .Where(x => x.campus.CF_College.SelectMany(w => w.CF_StaffManageCollege).Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.Department:
- return queryWithCampus
- .Where(x => x.campus.CF_College.SelectMany(w => w.CF_Department).SelectMany(w => w.CF_StaffManageDepartment)
- .Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.Assistant:
- return query.Where(x => false);
- case SYS_DataRange.Teacher:
- return queryWithCampus
- .Where(x => x.campus.CF_College.SelectMany(w => w.CF_Staff).Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- }
- }
- protected IQueryable<T> GetQueryByDataRangeByCollege<T>(IQueryable<T> query, Expression<Func<T, Guid?>> collegeColumn = null)
- {
- ExpressionFactory<T> factory = new ExpressionFactory<T>(query);
- var outerExp = collegeColumn;
- if (collegeColumn == null)
- {
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "CollegeID"), typeof(Guid?)), paramter);
- }
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- if (curUser.IsStudent)
- {
- return query;
- }
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
- var queryWithCollege = query
- .Join(UnitOfWork.CF_College.AsQueryable(), outerExp, (x => x.CollegeID), ((x, y) => new { result = x, college = y }));
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return query;
- case SYS_DataRange.Campus:
- return queryWithCollege
- .Where(x => x.college.CF_Campus.CF_StaffManageCampus.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.College:
- return queryWithCollege
- .Where(x => x.college.CF_StaffManageCollege.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.Department:
- return queryWithCollege
- .Where(x => x.college.CF_Department.SelectMany(w => w.CF_StaffManageDepartment).Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.Assistant:
- return query.Where(x => false);
- case SYS_DataRange.Teacher:
- return queryWithCollege
- .Where(x => x.college.CF_Staff.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- }
- }
- protected IQueryable<T> GetQueryByDataRangeByDepartment<T>(IQueryable<T> query, Expression<Func<T, Guid?>> departmentColumn = null)
- {
- ExpressionFactory<T> factory = new ExpressionFactory<T>(query);
- var outerExp = departmentColumn;
- if (departmentColumn == null)
- {
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "DepartmentID"), typeof(Guid?)), paramter);
- }
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- if (curUser.IsStudent)
- {
- return query;
- }
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetRoleDataRange(curUser.RoleID, menuNo);
- var queryWithDepartment = query
- .Join(UnitOfWork.CF_Department.AsQueryable(), outerExp, (x => x.DepartmentID), ((x, y) => new { result = x, department = y }));
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return query;
- case SYS_DataRange.Campus:
- return queryWithDepartment
- .Where(x => x.department.CF_College.CF_Campus.CF_StaffManageCampus.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.College:
- return queryWithDepartment
- .Where(x => x.department.CF_College.CF_StaffManageCollege.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.Department:
- return queryWithDepartment
- .Where(x => x.department.CF_StaffManageDepartment.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- case SYS_DataRange.Assistant:
- return query.Where(x => false);
- case SYS_DataRange.Teacher:
- return queryWithDepartment
- .Where(x => x.department.CF_Staff.Any(w => w.UserID == curUserID))
- .Select(x => x.result);
- }
- }
- protected bool IsUserInDataRange<T>(List<Guid> formIDList, Guid userID, Expression<Func<T, Guid?>> userColumn = null) where T : class
- {
- var outerExp = userColumn;
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- if (userColumn == null)
- {
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "CreateUserID"), typeof(Guid?)), paramter);
- }
- var containMethodInfo = formIDList.GetType().GetMethod("Contains");
- var keyExp = Expression.Lambda<Func<T, bool>>(
- Expression.Call(Expression.Constant(formIDList), containMethodInfo, Expression.Property(paramter, TableKeyDictionary.GetKeyName<T>())),
- paramter
- );
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetUserDataRange(userID, menuNo);
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return true;
- case SYS_DataRange.Campus:
- return UnitOfWork.Set<T>().Where(keyExp)
- .Join(
- UnitOfWork.CF_Campus.SelectMany(x => x.CF_StaffManageCampus).Select(x => x.CF_Staff)
- .Where(x => x.UserID == userID),
- outerExp, (x => x.UserID), ((x, y) => x))
- .Count() == formIDList.Count;
- case SYS_DataRange.College:
- return UnitOfWork.Set<T>().Where(keyExp)
- .Join(
- UnitOfWork.CF_College.SelectMany(x => x.CF_StaffManageCollege).Select(x => x.CF_Staff)
- .Where(x => x.UserID == userID),
- outerExp, (x => x.UserID), ((x, y) => x))
- .Count() == formIDList.Count;
- case SYS_DataRange.Department:
- return UnitOfWork.Set<T>().Where(keyExp)
- .Join(
- UnitOfWork.CF_Department.SelectMany(x => x.CF_StaffManageDepartment).Select(x => x.CF_Staff)
- .Where(x => x.UserID == userID),
- outerExp, (x => x.UserID), ((x, y) => x))
- .Count() == formIDList.Count;
- case SYS_DataRange.Assistant:
- return false;
- case SYS_DataRange.Teacher:
- return UnitOfWork.Set<T>().Where(keyExp)
- .Join(
- UnitOfWork.CF_Staff.Where(x => x.UserID == userID),
- outerExp, (x => x.UserID), ((x, y) => x))
- .Count() == formIDList.Count;
- }
- }
- protected bool IsUserInDataRangeByDepartment<T>(List<Guid> formIDList, Guid userID, Expression<Func<T, Guid?>> departmentColumn = null) where T : class
- {
- var outerExp = departmentColumn;
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- if (departmentColumn == null)
- {
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "DepartmentID"), typeof(Guid?)), paramter);
- }
- var containMethodInfo = formIDList.GetType().GetMethod("Contains");
- var keyExp = Expression.Lambda<Func<T, bool>>(
- Expression.Call(Expression.Constant(formIDList), containMethodInfo, Expression.Property(paramter, TableKeyDictionary.GetKeyName<T>())),
- paramter
- );
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetUserDataRange(userID, menuNo);
- var queryWithDepartment = UnitOfWork.Set<T>().Where(keyExp)
- .Join(UnitOfWork.CF_Department.AsQueryable(), outerExp, (x => x.DepartmentID), ((x, y) => new { result = x, department = y }));
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return true;
- case SYS_DataRange.Campus:
- return queryWithDepartment
- .Where(x => x.department.CF_College.CF_Campus.CF_StaffManageCampus.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.College:
- return queryWithDepartment
- .Where(x => x.department.CF_College.CF_StaffManageCollege.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.Department:
- return queryWithDepartment
- .Where(x => x.department.CF_StaffManageDepartment.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.Assistant:
- return false;
- case SYS_DataRange.Teacher:
- return queryWithDepartment
- .Where(x => x.department.CF_Staff.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- }
- }
- protected bool IsUserInDataRangeByCollege<T>(List<Guid> formIDList, Guid userID, Expression<Func<T, Guid?>> collegeColumn = null) where T : class
- {
- var outerExp = collegeColumn;
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- if (collegeColumn == null)
- {
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "CollegeID"), typeof(Guid?)), paramter);
- }
- var containMethodInfo = formIDList.GetType().GetMethod("Contains");
- var keyExp = Expression.Lambda<Func<T, bool>>(
- Expression.Call(Expression.Constant(formIDList), containMethodInfo, Expression.Property(paramter, TableKeyDictionary.GetKeyName<T>())),
- paramter
- );
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetUserDataRange(userID, menuNo);
- var queryWithCollege = UnitOfWork.Set<T>().Where(keyExp)
- .Join(UnitOfWork.CF_College.AsQueryable(), outerExp, (x => x.CollegeID), ((x, y) => new { result = x, college = y }));
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return true;
- case SYS_DataRange.Campus:
- return queryWithCollege
- .Where(x => x.college.CF_Campus.CF_StaffManageCampus.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.College:
- return queryWithCollege
- .Where(x => x.college.CF_StaffManageCollege.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.Department:
- return queryWithCollege
- .Where(x => x.college.CF_Department.SelectMany(w => w.CF_StaffManageDepartment).Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.Assistant:
- return false;
- case SYS_DataRange.Teacher:
- return queryWithCollege
- .Where(x => x.college.CF_Staff.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- }
- }
- protected bool IsUserInDataRangeByCampusID<T>(List<Guid> formIDList, Guid userID, Expression<Func<T, Guid?>> campusColumn = null) where T : class
- {
- var outerExp = campusColumn;
- ParameterExpression paramter = Expression.Parameter(typeof(T));
- if (campusColumn == null)
- {
- outerExp = Expression.Lambda<Func<T, Guid?>>(Expression.Convert(Expression.Property(paramter, "CampusID"), typeof(Guid?)), paramter);
- }
- var containMethodInfo = formIDList.GetType().GetMethod("Contains");
- var keyExp = Expression.Lambda<Func<T, bool>>(
- Expression.Call(Expression.Constant(formIDList), containMethodInfo, Expression.Property(paramter, TableKeyDictionary.GetKeyName<T>())),
- paramter
- );
- var menuNo = HttpHelper.GetMenuNo();
- if (string.IsNullOrEmpty(menuNo))
- {
- menuNo = HttpContext.Current.Request.UrlReferrer.GetQueryStringByPath("FromMNU");
- }
- SYS_DataRange dataRange = DataRangeDAL.GetUserDataRange(userID, menuNo);
- var queryWithCampus = UnitOfWork.Set<T>().Where(keyExp)
- .Join(UnitOfWork.CF_Campus.AsQueryable(), outerExp, (x => x.CampusID), ((x, y) => new { result = x, campus = y }));
- switch (dataRange)
- {
- case SYS_DataRange.All:
- default:
- return true;
- case SYS_DataRange.Campus:
- return queryWithCampus
- .Where(x => x.campus.CF_StaffManageCampus.Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.College:
- return queryWithCampus
- .Where(x => x.campus.CF_College.SelectMany(w => w.CF_StaffManageCollege).Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.Department:
- return queryWithCampus
- .Where(x => x.campus.CF_College.SelectMany(w => w.CF_Department).SelectMany(w => w.CF_StaffManageDepartment).Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- case SYS_DataRange.Assistant:
- return false;
- case SYS_DataRange.Teacher:
- return queryWithCampus
- .Where(x => x.campus.CF_College.SelectMany(w => w.CF_Staff).Any(w => w.UserID == userID))
- .Count() == formIDList.Count;
- }
- }
- public void SetNewStatus<T>(T entity)
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- var curUserID = curUser.UserID;
- //typeof(T).GetProperty(TableKeyDictionary.GetKeyName(entity))
- // .SetValue(entity, Guid.NewGuid(), null);
- dynamic dyEntity = entity;
- dyEntity.RecordStatus = (int)SYS_STATUS.USABLE;
- dyEntity.CreateUserID = curUserID;
- dyEntity.ModifyUserID = curUserID;
- dyEntity.ModifyTime = dyEntity.CreateTime = DateTime.Now;
- }
- public void SetNewStatus<T>(T entity, int recordStatus)
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- Guid? curUserID = null;
- if (curUser != null)
- {
- curUserID = curUser.UserID;
- }
- //typeof(T).GetProperty(TableKeyDictionary.GetKeyName(entity))
- // .SetValue(entity, Guid.NewGuid(), null);
- dynamic dyEntity = entity;
- dyEntity.RecordStatus = recordStatus;
- dyEntity.CreateUserID = curUserID;
- dyEntity.ModifyUserID = curUserID;
- dyEntity.ModifyTime = dyEntity.CreateTime = DateTime.Now;
- }
- public void SetModifyStatus<T>(T entity)
- {
- var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;
- Guid? curUserID = null;
- if (curUser != null)
- {
- curUserID = curUser.UserID;
- }
- dynamic dyEntity = entity;
- dyEntity.ModifyUserID = curUserID;
- dyEntity.ModifyTime = DateTime.Now;
- }
- }
- }
|