/// <summary>
 /// 添加用户岗位关系
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public static bool AddUserPositionRelation(Model.Admin.MSUserPositionRelation entity)
 {
     if (entity == null)
     {
         return(false);
     }
     return(DAL.Admin.MSUserPositionRelationDal.Add(entity));
 }
        public ActionResult AddTeacherCallBack(Models.Admin.MSUserInfoModel InModel)
        {
            string msg = "OK";

            // 添加用户
            Model.Admin.MSUserInfo userInfo = new Model.Admin.MSUserInfo()
            {
                UserName   = InModel.UserName,
                Password   = Security.getMD5ByStr(InModel.Password),
                RealName   = InModel.RealName,
                RoleID     = (int)Model.RoleType.教职工,
                SchoolID   = 1, //默认学院
                MajorID    = Converter.TryToInt64(InModel.MajorId),
                ClassID    = 0,
                Gender     = InModel.Gender,
                Telephone  = InModel.Telephone,
                QQ         = InModel.QQ,
                Email      = InModel.Email,
                Remark     = InModel.Remark,
                CreateTime = DateTime.Now,
                CreateUser = Identity.LoginUserInfo.UserID,
            };
            userInfo.UserID = BLL.Admin.MSUserInfoBll.AddUserInfo(userInfo);
            if (userInfo.UserID > 0)
            {
                // 添加默认岗位
                Model.Admin.MSUserPositionRelation relation = new Model.Admin.MSUserPositionRelation()
                {
                    UserID     = userInfo.UserID,
                    CreateTime = DateTime.Now,
                    CreateUser = Identity.LoginUserInfo.UserID,
                };
                if (InModel.IsPresident == "1")
                {
                    // 院长
                    relation.PositionID = userInfo.SchoolID;//院长岗位ID
                }
                else
                {
                    // 讲师
                    relation.PositionID = MSPositionInfoBll.GetPositionIdByDepartmentIdAndPositionType(userInfo.MajorID, (int)Model.PositionType.讲师);
                }
                MSUserPositionRelationBll.AddUserPositionRelation(relation);
            }
            else
            {
                msg = "添加失败,请重试";
            }
            return(Json(new { Message = msg }));
        }
        /// <summary>
        /// 增加实体
        /// </summary>
        public static bool Add(Model.Admin.MSUserPositionRelation entity)
        {
            var sql        = @"
                        INSERT INTO [MSUserPositionRelation]
                               (
                                [UserID]
                                ,[PositionID]
                                ,[CreateTime]
                                ,[CreateUser]
                                ,[Deleted]

                               )
                         VALUES
                               (
                                @UserID
                                ,@PositionID
                                ,@CreateTime
                                ,@CreateUser
                                ,@Deleted
                               )
                    ";
            var parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter()
            {
                ParameterName = "@UserID", Value = entity.UserID
            });
            parameters.Add(new SqlParameter()
            {
                ParameterName = "@PositionID", Value = entity.PositionID
            });
            parameters.Add(new SqlParameter()
            {
                ParameterName = "@CreateTime", Value = entity.CreateTime
            });
            parameters.Add(new SqlParameter()
            {
                ParameterName = "@CreateUser", Value = entity.CreateUser
            });
            parameters.Add(new SqlParameter()
            {
                ParameterName = "@Deleted", Value = entity.Deleted
            });


            int i = SqlHelper.ExecuteNonQuery(sql, parameters.ToArray());

            return(i > 0 ? true : false);
        }
        public static bool SetDirectorInfo(long departmentId, long directorId, int positionCode, out string errorMsg)
        {
            errorMsg = "";
            //查询部门信息
            Model.Admin.MSDepartmentInfo departmentInfo = DAL.Admin.MSDepartmentInfoDal.GetByDepartmentID(departmentId);

            if (departmentInfo == null)
            {
                errorMsg = "数据不存在,请刷新列表重新操作!";
                return(false);
            }

            //查询部门指定岗位信息
            Model.Admin.MSPositionInfo positionInfo = DAL.Admin.MSPositionInfoDal.GetByDepartmentIdAndPositionType(departmentId, positionCode);
            if (positionInfo == null)
            {
                errorMsg = "数据错误,请联系管理员!";
                return(false);
            }

            //查询该岗位有没有绑定用户
            List <Model.Admin.MSUserPositionRelation> relationList = DAL.Admin.MSUserPositionRelationDal.GetListByPositionID(positionInfo.PositionID);

            if (relationList != null && relationList.Count > 0)
            {
                Model.Admin.MSUserPositionRelation relationEntity = relationList[0];
                //更新用户ID
                DAL.Admin.MSUserPositionRelationDal.UpdateUserIDByRelationId(relationEntity.RelationID, directorId);
            }
            else
            {
                //未绑定插入
                Model.Admin.MSUserPositionRelation relationEntity = new MSUserPositionRelation()
                {
                    PositionID = positionInfo.PositionID,
                    UserID     = directorId,
                    Deleted    = 0,
                    CreateTime = DateTime.Now,
                    CreateUser = Model.Identity.LoginUserInfo.UserID
                };
                DAL.Admin.MSUserPositionRelationDal.Add(relationEntity);
            }

            return(true);
        }