public static void saveCreatedDepartment( BizEntitySchema bizEntitySchema, Department department, Department departmentParent, EnouFlowOrgMgmtContext db) { if (!db.departments.ToList().Contains(department)) //新创建尚未存入DB的Department { //db.departments.Add(department); department.assistBizEntitySchemaId = bizEntitySchema.bizEntitySchemaId; bizEntitySchema.departments.Add(department); } //验证一个Department不能有多个Parent Department if (db.departmentParentChildRelations.ToList().Where( r => r.departmentIdChild == department.departmentId). ToList().Count() > 0) { throw new Exception( string.Format("部门'{0}'已属于其他部门", department.name)); } DepartmentParentChildRelation departmentParentChildRelation = db.departmentParentChildRelations.Create(); departmentParentChildRelation.assistBizEntitySchemaId = bizEntitySchema.bizEntitySchemaId; departmentParentChildRelation.departmentChild = department; if (departmentParent != null) { departmentParentChildRelation.departmentParent = departmentParent; } bizEntitySchema.departmentParentChildRelations.Add(departmentParentChildRelation); db.SaveChanges(); }
public static Department getDepartment(int id) { using (EnouFlowOrgMgmtContext db = new EnouFlowOrgMgmtContext()) { return(getDepartment(id, db)); } }
private static void addFlowInstanceFriendlyLog( FlowInstance flowInstance, int flowActionRequestId, string currentActivityName, int paticipantUserId, int?delegateeUserId, string actionName, string paticipantMemo, EnouFlowInstanceContext db) { var log = db.flowFriendlyLogs.Create(); log.FlowInstance = flowInstance; log.flowActionRequestId = flowActionRequestId; log.currentActivityName = currentActivityName; using (var orgDb = new EnouFlowOrgMgmtContext()) { UserHelper userHelper = new UserHelper(orgDb); var paticipant = userHelper.getUserDTO(paticipantUserId); log.paticipantName = paticipant.name + (paticipant.englishName == null ? "" : "/" + paticipant.englishName); if (delegateeUserId.HasValue) { var delegatee = userHelper.getUserDTO(delegateeUserId.Value); log.delegateeName = delegatee.name + (delegatee.englishName == null ? "" : "/" + delegatee.englishName); } } log.actionName = actionName; log.paticipantMemo = paticipantMemo; db.flowFriendlyLogs.Add(log); }
public static Department getUserDefaultDepartment(int userId) { using (var db = new EnouFlowOrgMgmtContext()) { return(getUserDefaultDepartment(userId, db)); } }
public static UserDTO getUserDTO(string guid) { using (EnouFlowOrgMgmtContext db = new EnouFlowOrgMgmtContext()) { return(getUserDTO(guid, db)); } }
public static List <UserDTO> getUserDTOsOfPositionInDepartment( int id, UserPositionToDepartment position) { using (var db = new EnouFlowOrgMgmtContext()) { return(getUserDTOsOfPositionInDepartment(id, position, db)); } }
public void constructor_WithDBContext_HasDBContext() { using (var db = new EnouFlowOrgMgmtContext()) { OrgHelper o = new OrgHelper(db); Assert.IsNotNull(o._dbContext); } }
public static Paticipant getPaticipantFromGuid(string guid) { using (EnouFlowOrgMgmtContext db = new EnouFlowOrgMgmtContext()) { #region 如果为用户 var user = new UserHelper(db).getObject(guid); if (user != null) { return(new Paticipant("user", new PaticipantDigest( user.name, user.guid, user.userId, null, null ) )); } #endregion #region 如果为角色 var role = new RoleHelper(db).getObject(guid); if (role != null) { return(new Paticipant("role", new PaticipantDigest( role.name, role.guid, null, role.roleId, null ) )); } #endregion #region 如果为流程动态用户 using (var flowTemplateDb = new EnouFlowTemplateDbContext()) { var flowDynamicUser = flowTemplateDb.flowDynamicUsers.Where( obj => obj.guid == guid).FirstOrDefault(); if (flowDynamicUser != null) { return(new Paticipant("dynamic", new PaticipantDigest( flowDynamicUser.name, flowDynamicUser.guid, null, null, flowDynamicUser.flowDynamicUserId ) )); } } #endregion } return(null); }
public static bool isOrgChangeAllowed(int id, Org value, EnouFlowOrgMgmtContext db) { if (db.orgs.AsNoTracking().Where(org => org.orgId == id).ToList().FirstOrDefault().guid != value.guid) { throw new GuidNotAllowedToChangeException("不能修改对象GUID!"); } return(true); }
public static bool isRoleTypeChangeAllowed(int id, RoleType value, EnouFlowOrgMgmtContext db) { if (db.roleTypes.AsNoTracking().Where( obj => obj.roleTypeId == id).ToList().FirstOrDefault().guid != value.guid) { throw new GuidNotAllowedToChangeException("不能修改对象GUID!"); } return(true); }
public static bool isBizEntityChangeAllowed(int id, BizEntity value, EnouFlowOrgMgmtContext db) { if (db.bizEntities.AsNoTracking().Where( bizEntity => bizEntity.bizEntityId == id).ToList().FirstOrDefault().guid != value.guid) { throw new GuidNotAllowedToChangeException("不能修改对象GUID!"); } return(true); }
public static bool removeDepartment(int id, EnouFlowOrgMgmtContext db) { var department = db.departments.Find(id); if (department != null && isDepartmentRemovable(id, db)) { department.isVisible = false; } db.SaveChanges(); return(true); }
public static RoleTypeDTO convertRoleType2DTO(RoleType obj, EnouFlowOrgMgmtContext db) { return(new RoleTypeDTO() { roleTypeId = obj.roleTypeId, guid = obj.guid, name = obj.name, isVisible = obj.isVisible, createTime = obj.createTime, roles = obj.getRolesBelongTo(db).Select( role => convertRole2DTO(role, db)).ToList() }); }
public static bool removeBizEntity(int id, EnouFlowOrgMgmtContext db) { var bizEntity = db.bizEntities.Find(id); if (bizEntity != null && isBizEntityRemovable(id, db)) { bizEntity.isVisible = false; } db.SaveChanges(); return(true); }
public static void unsetRole_RoleType(int id, RoleType roleType, EnouFlowOrgMgmtContext db) { var role = db.roles.Find(id); if (role.getRoleTypesBelongTo(db, false) .Contains(roleType)) { var r = role.role_RoleTypeRelations.Where(x => x.assistRoleTypeId == roleType.roleTypeId). ToList().FirstOrDefault(); r.isValid = false; db.SaveChanges(); } }
public static void updateUserPositionToDepartment( Department department, User user, EnouFlowOrgMgmtContext db, UserPositionToDepartment userPositionToDepartment) { var relation = db.departmentUserRelations.Where(obj => obj.assistUserId == user.userId && obj.assistDepartmentId == department.departmentId). FirstOrDefault(); if (relation != null) { relation.userPosition = userPositionToDepartment; } db.SaveChanges(); }
private static bool isDepartmentRemovable(int id, EnouFlowOrgMgmtContext db) { var department = db.departments.Find(id); #region 能删除带有子节点的Department if (db.departmentParentChildRelations.ToList().Where( r => r.departmentParent == department && r.departmentChild.isVisible).Count() > 0) { throw new DataLogicException("不能删除带有子节点的Department"); } #endregion return(true); }
public static void unsetUserRole(int id, Role role, EnouFlowOrgMgmtContext db) { var user = db.users.Find(id); if (user.getRolesBelongTo(db) .Contains(role)) { var r = user.roleUserRelations.Where(x => x.assistRoleId == role.roleId). ToList().FirstOrDefault(); r.isValid = false; db.SaveChanges(); } }
public static void unsetUserDepartment(int id, Department department, EnouFlowOrgMgmtContext db) { var user = db.users.Find(id); if (user.getDepartmentsBelongTo(db) .Contains(department)) { var r = user.departmentUserRelations.Where(x => x.assistDepartmentId == department.departmentId). ToList().FirstOrDefault(); r.isValid = false; db.SaveChanges(); } }
public static bool isBizEntityRemovable(int id, EnouFlowOrgMgmtContext db) { var bizEntity = db.bizEntities.Find(id); #region 能删除带有子节点的BizEntity if (db.bizEntityRelationOnOrgSchemas.ToList().Where( r => r.bizEntityParent == bizEntity && r.bizEntityChild.isVisible).Count() > 0) { throw new DataLogicException("不能删除带有子节点的BizEntity"); } #endregion return(true); }
public void getPaticipantFromGuid_validUserGuid_returnUserPaticipant() { using (EnouFlowOrgMgmtContext dbOrg = new EnouFlowOrgMgmtContext()) { UserHelper userHelper = new UserHelper(dbOrg); var user = userHelper.createObject(); user.name = "Integration_Test_XXXYYYZZZ"; userHelper.saveCreatedObject(user); Paticipant result = FlowTemplateDefHelper.getPaticipantFromGuid(user.guid); Assert.NotNull(result); Assert.AreEqual(result.PaticipantType, "user"); Assert.AreEqual(result.PaticipantObj.guid, user.guid); } }
public void getPaticipantFromGuid_validRoleGuid_returnRolePaticipant() { using (EnouFlowOrgMgmtContext dbOrg = new EnouFlowOrgMgmtContext()) { RoleHelper roleHelper = new RoleHelper(dbOrg); var role = roleHelper.createObject(); role.name = "Integration_Test_XXXYYYZZZ"; roleHelper.saveCreatedObject(role); Paticipant result = FlowTemplateDefHelper.getPaticipantFromGuid(role.guid); Assert.NotNull(result); Assert.AreEqual(result.PaticipantType, "role"); Assert.AreEqual(result.PaticipantObj.guid, role.guid); } }
public static Department getUserDefaultDepartment( int userId, EnouFlowOrgMgmtContext db) { var departmentUserRelation = db.departmentUserRelations.Where( obj => obj.assistUserId == userId && obj.isValid).FirstOrDefault(); if (departmentUserRelation != null) { return(db.departments.Find( departmentUserRelation.assistDepartmentId)); } else { return(null); } }
public static List <RoleDTO> getAllRoleDTOs( EnouFlowOrgMgmtContext db, bool includingInvalid = true) { IEnumerable <Role> roles; if (includingInvalid) { roles = db.roles; } else { roles = db.roles.Where(role => role.isVisible == true); } return(db.roles.ToList().Select( role => { return convertRole2DTO(role, db); }).ToList()); }
public static List <UserDTO> getUserDTOsOfPositionInDepartment( int id, UserPositionToDepartment position, EnouFlowOrgMgmtContext db) { var relations = db.departmentUserRelations.Where( obj => obj.assistDepartmentId == id && obj.isValid && obj.userPosition == position).ToList(); if (relations == null || relations.Count() == 0) { return(null); } else { return(relations.Select(obj => getUserDTO(obj.assistUserId)).ToList()); } }
public static RoleDTO convertRole2DTO(Role obj, EnouFlowOrgMgmtContext db) { return(new RoleDTO() { roleId = obj.roleId, guid = obj.guid, name = obj.name, englishName = obj.englishName, displayName = obj.displayName, code = obj.code, indexNumber = obj.indexNumber, isVisible = obj.isVisible, createTime = obj.createTime, users = obj.getUsersBelongTo(db).Select( u => convertUser2DTO(u, db)).ToList(), }); }
public static BizEntitySchemaDTO convertBizEntitySchema2DTO(BizEntitySchema obj, EnouFlowOrgMgmtContext db) { return(new BizEntitySchemaDTO() { bizEntitySchemaId = obj.bizEntitySchemaId, guid = obj.guid, name = obj.name, shortName = obj.shortName, displayName = obj.displayName, code = obj.code, indexNumber = obj.indexNumber, createTime = obj.createTime, isVisible = obj.isVisible, rootDepartments = obj.getRootDepartments(db). Select(d => convertDepartment2DTO(d, db)).ToList() }); }
public static void saveCreatedBizEntity(OrgSchema orgSchema, BizEntity bizEntity, BizEntity bizEntityParent, EnouFlowOrgMgmtContext db, bool removeExistingRelation = false) { if (!db.bizEntities.ToList().Contains(bizEntity)) //新创建尚未存入DB的BizEntity { db.bizEntities.Add(bizEntity); } var hasExistingRelation = orgSchema.bizEntityRelationOnOrgSchemas.ToList().Where( bro => bro.bizEntityIdChild == bizEntity.bizEntityId ).ToList().Count() > 0; //验证不能属于同一OrgSchema下的多于一个Parent BizEntity if (hasExistingRelation) { if (!removeExistingRelation) { throw new Exception( string.Format("业务实体'{0}'在组织结构方案'{1}'内已有所属父实体.", bizEntity.name, orgSchema.name)); } else //Remove Existing Relation { orgSchema.bizEntityRelationOnOrgSchemas.Remove( orgSchema.bizEntityRelationOnOrgSchemas.Where( bro => bro.bizEntityIdChild == bizEntity.bizEntityId) .FirstOrDefault()); } } BizEntityRelationOnOrgSchema bizEntityRelationOnOrgSchema = db.bizEntityRelationOnOrgSchemas.Create(); bizEntityRelationOnOrgSchema.assistOrgSchemaId = orgSchema.orgSchemaId; bizEntityRelationOnOrgSchema.bizEntityChild = bizEntity; if (bizEntityParent != null) { bizEntityRelationOnOrgSchema.bizEntityParent = bizEntityParent; } orgSchema.bizEntityRelationOnOrgSchemas.Add(bizEntityRelationOnOrgSchema); db.SaveChanges(); }
public static void setUserRole(int id, Role role, EnouFlowOrgMgmtContext db) { var user = db.users.Find(id); #region check whether relation already setted, then re-set to valid if (user.getRolesBelongTo(db, false) .Contains(role)) { var r = user.roleUserRelations.Where(x => x.assistRoleId == role.roleId). ToList().FirstOrDefault(); r.isValid = true; db.SaveChanges(); return; } #endregion saveCreatedRoleUserRelation(role, user, db); }
public static void saveCreatedOrg(Org org, EnouFlowOrgMgmtContext db) { //顶级机构名字唯一性判断 if (db.orgs.ToList().Exists( o => o.name == org.name && o.orgId != org.orgId)) { throw new NameDuplicationException("不能创建同名的顶级机构."); } //只能有一个默认顶级机构 if (db.orgs.ToList().Exists( o => o.isDefault && o.orgId != org.orgId)) { org.isDefault = false; } db.orgs.Add(org); db.SaveChanges(); }