using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions; using System.Text; using Bowin.Common.Linq; using Bowin.Common.Linq.Entity; using EMIS.ViewModel.DQPSystem; using EMIS.ViewModel; using EMIS.DataLogic.DQPSystem; using EMIS.Entities; using EMIS.DataLogic.Repositories; using System.Web; namespace EMIS.CommonLogic.DQPSystem { public class SOCDocServices : BaseServices, ISOCDocServices { public RoleRepository RoleRepository { get; set; } public CollegeRepository CollegeRepository { get; set; } public DepartmentRepository DepartmentRepository { get; set; } public SOCDocDAL SOCDocDAL { get; set; } public IGridResultSet GetSOCDocViewList(ConfiguretView socDocConditionView, int? socDocTypeID, Guid? createCollegeID, Guid? targetRoleID, Guid? targetCollegeID, int? pageIndex, int? pageSize) { Expression> exp = (x => true); Expression> staffExp = (x => true); if (socDocTypeID.HasValue) { exp = exp.And(x => x.SOCDocTypeID == socDocTypeID); } if (createCollegeID.HasValue) { staffExp = staffExp.And(x => x.CollegeID == createCollegeID); } if (targetRoleID.HasValue) { exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID)); } if (targetCollegeID.HasValue) { exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID)); } var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp); if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute)) query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue); query = this.GetQueryByDataRangeByCollege(query, (x => x.CreateCollegeID)); query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime); return query.ToGridResultSet(pageIndex, pageSize); } public List GetSOCDocViewList(ConfiguretView socDocConditionView, int? socDocTypeID, Guid? createCollegeID, Guid? targetRoleID, Guid? targetCollegeID) { Expression> exp = (x => true); Expression> staffExp = (x => true); if (socDocTypeID.HasValue) { exp = exp.And(x => x.SOCDocTypeID == socDocTypeID); } if (createCollegeID.HasValue) { staffExp = staffExp.And(x => x.CollegeID == createCollegeID); } if (targetRoleID.HasValue) { exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID)); } if (targetCollegeID.HasValue) { exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID)); } var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp); if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute)) query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue); query = this.GetQueryByDataRangeByCollege(query, (x => x.CreateCollegeID)); query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime); return query.ToList(); } public IGridResultSet GetUserSOCDocViewList(ConfiguretView socDocConditionView, Guid roleID, int? socDocTypeID, Guid? createCollegeID, Guid? targetRoleID, Guid? targetCollegeID, int? pageIndex, int? pageSize) { Expression> exp = (x => x.RecordStatus == (int)CF_GeneralPurpose.IsYes); Expression> staffExp = (x => true); var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current; var DepartmentID=SOCDocDAL.StaffRepository.GetList(x=>x.UserID==curUser.UserID).Select(x=>x.DepartmentID).FirstOrDefault(); exp=exp.And(x=>(x.CF_Department.Count()==0||x.CF_Department.Any(w=>w.DepartmentID==DepartmentID))); exp = exp.And(x => (x.CF_College.Count() == 0 || x.CF_College.AsQueryable().Any(this.GetDataRageExpressionByCollege(w => w.CollegeID)))); exp = exp.And(x => (x.Sys_Role.Count() == 0 || x.Sys_Role.Any(w => w.RoleID == roleID))); if (socDocTypeID.HasValue) { exp = exp.And(x => x.SOCDocTypeID == socDocTypeID); } if (createCollegeID.HasValue) { staffExp = staffExp.And(x => x.CollegeID == createCollegeID); } if (targetRoleID.HasValue) { exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID)); } if (targetCollegeID.HasValue) { exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID)); } var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp); if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute)) query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue); query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime); return query.ToGridResultSet(pageIndex, pageSize); } public List GetUserSOCDocViewList(ConfiguretView socDocConditionView, Guid roleID, int? socDocTypeID, Guid? createCollegeID, Guid? targetRoleID, Guid? targetCollegeID) { Expression> exp = (x => x.RecordStatus == (int)CF_GeneralPurpose.IsYes); Expression> staffExp = (x => true); exp = exp.And(x => (x.CF_College.Count() == 0 || x.CF_College.AsQueryable().Any(this.GetDataRageExpressionByCollege(w => w.CollegeID)))); exp = exp.And(x => (x.Sys_Role.Count() == 0 || x.Sys_Role.Any(w => w.RoleID == roleID))); if (socDocTypeID.HasValue) { exp = exp.And(x => x.SOCDocTypeID == socDocTypeID); } if (createCollegeID.HasValue) { staffExp = staffExp.And(x => x.CollegeID == createCollegeID); } if (targetRoleID.HasValue) { exp = exp.And(x => x.Sys_Role.Any(w => w.RoleID == targetRoleID)); } if (targetCollegeID.HasValue) { exp = exp.And(x => x.CF_Department.Any(w => w.CollegeID == targetCollegeID)); } var query = SOCDocDAL.GetSOCDocViewQueryable(exp, staffExp); if (!string.IsNullOrEmpty(socDocConditionView.ConditionValue) && !string.IsNullOrEmpty(socDocConditionView.Attribute)) query = query.DynamicWhere(socDocConditionView.Attribute, socDocConditionView.Condition, socDocConditionView.ConditionValue); query = query.OrderBy(x => x.SOCDocTypeID).ThenByDescending(x => x.CreateTime); return query.ToList(); } public void Save(SOCDocView documentView, IList targetRoleIDList, IList targetDepartmentIDList) { var document = new DQP_Document(); var targetRoleList = this.RoleRepository.GetList(x => targetRoleIDList.Contains(x.RoleID)).ToList(); var targetDepartmentList = this.DepartmentRepository.GetList(x => targetDepartmentIDList.Contains(x.DepartmentID)).ToList(); if (documentView.DocumentID != Guid.Empty) { document = this.SOCDocDAL.DocumentRepository.GetSingle(x => x.DocumentID == documentView.DocumentID, (x => x.Sys_Role), (x => x.CF_College)); this.SetModifyStatus(document); } else { document.DocumentID = Guid.NewGuid(); this.SetNewStatus(document); this.UnitOfWork.Add(document); } document.SOCDocTypeID = documentView.SOCDocTypeID; document.Title = documentView.Title; document.Content = documentView.Content; document.Sys_Role = new HashSet(); document.Sys_Role = new HashSet(targetRoleList); document.CF_Department = new HashSet(); document.CF_Department = new HashSet(targetDepartmentList); document.RecordStatus = (int)(documentView.IsShow ? CF_GeneralPurpose.IsYes : CF_GeneralPurpose.IsNo); UnitOfWork.Commit(); } public void Delete(IList documentIDList) { var documentList = this.SOCDocDAL.DocumentRepository.GetList(x => documentIDList.Contains(x.DocumentID), (x => x.Sys_Role), (x => x.CF_College)).ToList(); this.UnitOfWork.Delete(documentList, (x => x.Sys_Role)); this.UnitOfWork.Delete(documentList, (x => x.CF_College)); this.UnitOfWork.Delete(documentList, (x => x.CF_Department)); this.UnitOfWork.Delete(documentList); } public SOCDocView GetSOCDocView(Guid documentID) { var documentView = SOCDocDAL.GetSOCDocViewQueryable((x => x.DocumentID == documentID), (x => true)).FirstOrDefault(); return documentView; } } }