示例#1
0
 public static List <UserDTO> getUserDTOsOfPositionInDepartment(
     int id, UserPositionToDepartment position)
 {
     using (var db = new EnouFlowOrgMgmtContext())
     {
         return(getUserDTOsOfPositionInDepartment(id, position, db));
     }
 }
示例#2
0
        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();
        }
示例#3
0
        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());
            }
        }
示例#4
0
        public void setUserDepartment(int userId, Department department,
                                      UserPositionToDepartment userPosition)
        {
            Contract.Requires <DataLogicException>(_dbContext != null, "DbContext不能为空");
            Contract.Requires <DataLogicException>(department != null, "Department不能为空");

            var user = _dbContext.users.Find(userId);

            if (user == null)
            {
                throw new DataLogicException(string.Format("不存在的用户:id={0}!", userId));
            }

            // check whether relation already setted, then just re-set to valid and the userPosition
            if (user.getDepartmentsBelongTo(_dbContext, false).Contains(department))
            {
                bool changed = false;
                var  rs      = user.departmentUserRelations.ToList();
                foreach (var r in rs)
                {
                    if (r.assistDepartmentId == department.departmentId &&
                        (!r.isValid || r.userPosition != userPosition)) // only save if need modification
                    {
                        r.isValid      = true;
                        r.userPosition = userPosition;
                        changed        = true;
                    }
                    else if (r.assistDepartmentId != department.departmentId &&
                             OrgMgmtDBHelper.schemeMode == SchemeMode.simpleMode)
                    {// 如果是简单模式,则将该用户与其他部门存在的关系删除
                        r.isValid = false;
                        changed   = true;
                    }
                }
                if (changed)
                {
                    _dbContext.SaveChanges();
                }
            }
            else // otherwise create new relation object(如果DepartmentUserRelation不存在)
            {
                createDepartmentUserRelation(department, user, userPosition);
            }
        }
示例#5
0
        public static void setUserDepartment(int id, Department department,
                                             UserPositionToDepartment userPosition, EnouFlowOrgMgmtContext db)
        {
            var user = db.users.Find(id);

            #region check whether relation already setted, then re-set to valid and the userPosition
            if (user.getDepartmentsBelongTo(db, false)
                .Contains(department))
            {
                var r = user.departmentUserRelations.Where(x =>
                                                           x.assistDepartmentId == department.departmentId).
                        ToList().FirstOrDefault();
                r.isValid      = true;
                r.userPosition = userPosition;
                db.SaveChanges();
                return;
            }
            #endregion

            saveDepartmentUserRelation(department, user, db, userPosition);
        }
示例#6
0
        public void createDepartmentUserRelation(Department department, User user,
                                                 UserPositionToDepartment position = UserPositionToDepartment.normal)
        {
            Contract.Requires <DataLogicException>(_dbContext != null, "DbContext不能为空");
            Contract.Requires <DataLogicException>(department != null, "Department不能为空");
            Contract.Requires <DataLogicException>(user != null, "User不能为空");

            //不能重复建立部门-用户隶属关系(这里不限制用户可以同时属于多个部门)
            if (user.departmentUserRelations.ToList().Select(
                    r => r.assistDepartmentId).ToList().Contains(
                    department.departmentId))
            {
                throw new DataLogicException(
                          string.Format("用户'{0}'曾经属于部门'{1}', 需调用setUserDepartment调整",
                                        user.name, department.name));
            }

            // simpleMode下一个用户不能同时属于多个部门
            if (OrgMgmtDBHelper.schemeMode == SchemeMode.simpleMode)
            {
                if (user.departmentUserRelations.Where(r => r.isValid).ToList().Count() > 0)
                {
                    throw new DataLogicException(
                              string.Format(@"目前模式(simpleMode)下,一个用户不能同时属于多个部门.
可调用setUserDepartment强制取消其他部门的隶属关系"));
                }
            }

            var departmentUserRelation = _dbContext.departmentUserRelations.Create();

            user.departmentUserRelations.Add(departmentUserRelation);
            department.departmentUserRelations.Add(departmentUserRelation);
            departmentUserRelation.assistDepartmentId = department.departmentId;
            departmentUserRelation.assistUserId       = user.userId;
            departmentUserRelation.userPosition       = position;

            _dbContext.SaveChanges();
        }
示例#7
0
        public static void saveDepartmentUserRelation(Department department, User user,
                                                      EnouFlowOrgMgmtContext db, UserPositionToDepartment
                                                      userPositionToDepartment = UserPositionToDepartment.normal)
        {
            //不能重复建立部门-用户隶属关系(这里不限制用户可以同时属于多个部门)
            if (user.departmentUserRelations.ToList().Select(
                    r => r.assistDepartmentId).ToList().Contains(
                    department.departmentId))
            {
                return;

                throw new Exception(
                          string.Format("用户'{0}'已属于部门'{1}'", user.name, department.name));
            }

            // simpleMode下一个用户不能同时属于多个部门
            if (schemeMode == SchemeMode.simpleMode)
            {
                if (user.departmentUserRelations.ToList().Count() > 0)
                {
                    return;

                    throw new Exception(
                              string.Format("目前模式下,一个用户不能同时属于多个部门."));
                }
            }

            var departmentUserRelation = db.departmentUserRelations.Create();

            user.departmentUserRelations.Add(departmentUserRelation);
            department.departmentUserRelations.Add(departmentUserRelation);
            departmentUserRelation.assistDepartmentId = department.departmentId;
            departmentUserRelation.assistUserId       = user.userId;
            departmentUserRelation.userPosition       = userPositionToDepartment;

            db.SaveChanges();
        }