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); } }
public BaseResponse <bool> AddOfficerRecord(AddOfficerParameter parameter) { //1. 添加干部基础信息 //2. 添加此干部的积分申请(并设置为审批通过) //3. 修改当前积分 //4. 添加积分变更记录 BaseResponse <bool> response = new BaseResponse <bool>(); //iCMSDbContext dbContext = new iCMSDbContext(); OperationResult operResult = null; try { ExecuteDB.ExecuteTrans((dbContext) => { ValidateAddOfficer(dbContext, parameter); Officer officer = new Officer(); officer.Name = parameter.Name; officer.Gender = parameter.Gender; officer.IdentifyCardNumber = parameter.IdentifyNumber; var birth = DateTime.MinValue; var birthdayStr = Utilitys.GetBrithdayFromIdCard(parameter.IdentifyNumber); if (DateTime.TryParse(birthdayStr, out birth)) { officer.Birthday = birth; } officer.OrganizationID = parameter.OrganizationID; officer.PositionStr = parameter.PositionStr; officer.LevelID = parameter.LevelID; DateTime onOfficerDate = DateTime.MinValue; if (DateTime.TryParse(parameter.OnOfficeDate, out onOfficerDate)) { officer.OnOfficeDate = onOfficerDate; } officer.InitialScore = parameter.InitialScore; officer.CurrentScore = officer.InitialScore; officer.LastUpdateDate = DateTime.Now; officer.LastUpdateUserID = parameter.AddUserID; officer.AddUserID = parameter.AddUserID; operResult = dbContext.Officers.AddNew <Officer>(dbContext, officer); if (operResult.ResultType != EnumOperationResultType.Success) { throw new Exception("数据库操作异常"); } #region 操作日志 new LogManager().AddOperationLog(parameter.AddUserID, "添加干部", parameter.RequestIP); #endregion var scoreItemArray = scoreItemRepository.GetDatas <ScoreItem>(t => !t.IsDeleted, true).ToList(); int extraScore = 0; if (parameter.ApplyItemList.Any()) { parameter.ApplyItemList.ForEach(t => { ScoreApply scApply = new ScoreApply(); scApply.OfficerID = officer.OfficerID; scApply.ItemID = t.ItemID; var tempscoreItem = scoreItemArray.Where(s => s.ItemID == t.ItemID).FirstOrDefault(); if (tempscoreItem == null) { throw new Exception("积分条目已被删除"); } scApply.ItemScore = tempscoreItem.ItemScore; scApply.ApplyStatus = 1;//自动设置为审批通过 scApply.ProposeID = officer.AddUserID; scApply.AddUserID = officer.AddUserID; scApply.LastUpdateDate = DateTime.Now; scApply.LastUpdateUserID = officer.AddUserID; scApply.ApplySummary = t.ApplySummary; scApply.IsDeleted = false; operResult = dbContext.ScoreApplies.AddNew <ScoreApply>(dbContext, scApply); if (operResult.ResultType != EnumOperationResultType.Success) { throw new Exception("数据库操作异常"); } //保存变化的分值,最后更新CurrentScore extraScore += scApply.ItemScore; //保存积分更新历史记录表 ScoreChangeHistory his = new ScoreChangeHistory(); his.ApplyID = scApply.ApplyID; his.OfficerID = scApply.OfficerID; his.ItemID = scApply.ItemID; his.ItemScore = scApply.ItemScore; his.ProcessUserID = null; his.ProposeID = scApply.ProposeID; his.AddUserID = scApply.AddUserID; var scoreItem = dbContext.ScoreItems.Where(x => x.ItemID == his.ItemID).FirstOrDefault(); if (scoreItem != null) { var off = dbContext.Officers.Where(o => !o.IsDeleted && o.OfficerID == his.OfficerID).FirstOrDefault(); if (off != null) { var organ = dbContext.Organizations.Where(or => !or.IsDeleted && or.OrganID == off.OrganizationID).FirstOrDefault(); if (organ != null) { his.Content = string.Format("{0} {1} {2}", organ.OrganFullName, off.Name, scoreItem.ItemDescription); operResult = dbContext.ScoreChangeHistories.AddNew <ScoreChangeHistory>(dbContext, his); if (operResult.ResultType != EnumOperationResultType.Success) { throw new Exception("数据库操作异常"); } } } } }); } var officeIndb = dbContext.Officers.Where(t => t.OfficerID == officer.OfficerID && !t.IsDeleted).FirstOrDefault(); if (officeIndb != null) { officeIndb.CurrentScore += extraScore; dbContext.Officers.Update <Officer>(dbContext, officeIndb); } }); } catch (Exception e) { LogHelper.WriteLog(e); response.IsSuccessful = false; response.Reason = e.Message; } return(response); }