public BaseResponse <bool> EditOfficerRecord(EditOfficerParameter parameter)
 {
     if (Validate(parameter))
     {
         return(officerManager.EditOfficerRecord(parameter));
     }
     else
     {
         BaseResponse <bool> response = new BaseResponse <bool>();
         response.IsSuccessful = false;
         response.Reason       = "JWT_ERR";
         return(response);
     }
 }
        public BaseResponse <bool> EditOfficerRecord(EditOfficerParameter parameter)
        {
            BaseResponse <bool> response = new BaseResponse <bool>();

            try
            {
                #region 输入验证
                if (string.IsNullOrEmpty(parameter.Name))
                {
                    response.IsSuccessful = false;
                    response.Reason       = "干部名称不能为空";
                    return(response);
                }
                if (string.IsNullOrEmpty(parameter.IdentifyNumber))
                {
                    response.IsSuccessful = false;
                    response.Reason       = "身份证号不能为空";
                    return(response);
                }
                if (string.IsNullOrEmpty(parameter.OnOfficeDate))
                {
                    response.IsSuccessful = false;
                    response.Reason       = "请输入任职时间";
                    return(response);
                }

                if (parameter.OrganizationID < 1)
                {
                    response.IsSuccessful = false;
                    response.Reason       = "请选择单位";
                    return(response);
                }

                //var isExisted = officerRepository.GetDatas<Officer>(t => !t.IsDeleted && !string.IsNullOrEmpty(t.Name) && t.OfficerID != parameter.OfficerID && t.Name.Equals(parameter.Name), true).Any();
                //if (isExisted)
                //{
                //    response.IsSuccessful = false;
                //    response.Reason = "干部名称已存在";
                //    return response;
                //}

                var isExisted = officerRepository.GetDatas <Officer>(t => !t.IsDeleted && !string.IsNullOrEmpty(t.IdentifyCardNumber) && t.IdentifyCardNumber.Equals(parameter.IdentifyNumber) && t.OfficerID != parameter.OfficerID, true).Any();
                if (isExisted)
                {
                    throw new Exception("身份证号码重复");
                }

                if (!Utilitys.CheckIDCard(parameter.IdentifyNumber))
                {
                    throw new Exception("请输入合法的身份证号码");
                }
                using (iCMSDbContext dbContext = new iCMSDbContext())
                {
                    var updateUser = dbContext.HBUsers.Where(t => !t.IsDeleted && t.UserID == parameter.UpdateUserID).FirstOrDefault();
                    if (updateUser == null)
                    {
                        throw new Exception("数据异常");
                    }



                    int roleID = updateUser.RoleID;
                    switch (roleID)
                    {
                    case (int)EnumRoleType.SuperAdmin:
                        //超级管理员可以编辑任意单位的干部
                        break;

                    case (int)EnumRoleType.FirstLevelAdmin:
                        //一级管理员不能够编辑干部
                        throw new Exception("请使用二级管理员登陆,然后编辑干部");
                        break;

                    case (int)EnumRoleType.SecondLevelAdmin:
                        var organ = dbContext.Organizations.Where(t => !t.IsDeleted && t.OrganID == updateUser.OrganizationID).FirstOrDefault();
                        if (organ == null)
                        {
                            throw new Exception("数据异常");
                        }

                        //二级管理员只能够添加本单位的干部
                        if (updateUser.OrganizationID != parameter.OrganizationID)
                        {
                            string msg = string.Format("只能修改本单位({0})的干部", organ.OrganFullName);
                            throw new Exception(msg);
                        }
                        break;
                    }

                    //if (updateUser.OrganizationID != parameter.OrganizationID)
                    //{
                    //    string msg = string.Format("只能修改本单位({0})的干部", organ.OrganFullName);
                    //    throw new Exception(msg);
                    //}
                }

                #endregion

                var offIndb = officerRepository.GetDatas <Officer>(t => !t.IsDeleted && t.OfficerID == parameter.OfficerID, true).FirstOrDefault();
                if (offIndb == null)
                {
                    response.IsSuccessful = false;
                    response.Reason       = "编辑干部数据异常";
                    return(response);
                }
                offIndb.Name               = parameter.Name;
                offIndb.Gender             = parameter.Gender;
                offIndb.IdentifyCardNumber = parameter.IdentifyNumber;

                var birth    = Utilitys.GetBrithdayFromIdCard(parameter.IdentifyNumber);
                var birthDay = DateTime.MinValue;
                if (DateTime.TryParse(birth, out birthDay))
                {
                    offIndb.Birthday = birthDay;
                }

                offIndb.OrganizationID = parameter.OrganizationID;
                offIndb.PositionStr    = parameter.PositionStr;
                offIndb.LevelID        = parameter.LevelID;

                var onOfficeDate = DateTime.MinValue;
                if (DateTime.TryParse(parameter.OnOfficeDate, out onOfficeDate))
                {
                    offIndb.OnOfficeDate = onOfficeDate;
                }

                offIndb.Duty = parameter.Duty;
                //offIndb.InitialScore = parameter.InitialScore;

                var res = officerRepository.Update <Officer>(offIndb);
                if (res.ResultType != EnumOperationResultType.Success)
                {
                    throw new Exception("编辑干部发生异常");
                }
                return(response);
            }
            catch (Exception e)
            {
                response.IsSuccessful = false;

                response.Reason = e.Message;
                return(response);
            }
        }