/// <summary> /// 修改密码 /// </summary> /// <param name="userId">用户ID</param> /// <param name="srcPwd">原密码</param> /// <param name="newPwd">新密码</param> /// <returns></returns> public bool ChangePassword(string userId, string srcPwd, string newPwd) { if (string.IsNullOrEmpty(newPwd)) { throw new Exception("新密码不能为空!"); } var user = _dbContext.Set <Employee>().Where(s => s.Id == userId).FirstOrDefault(); if (user == null) { throw new Exception("用户不存在!"); } if (EncryptUtil.Md5Hash(srcPwd) == user.Password) { user.Password = EncryptUtil.Md5Hash(newPwd); _dbContext.SaveChanges(); return(true); } else { throw new Exception("原密码错误!"); } }
/// <summary> /// 医疗机构信息维护 /// </summary> /// <param name="source"></param> /// <returns></returns> public MedicalInstitutionDto AddOrUpdateMedicalInstitution(MedicalInstitutionDto source) { var isAddNew = string.IsNullOrEmpty(source.Id); if (isAddNew) { source.Id = Guid.NewGuid().ToString(); var entity = Mapper.Map <MedicalInstitutionDto, MedicalInstitution>(source); _dbContext.Set <MedicalInstitution>().Add(entity); } else { var target = _dbContext.Set <MedicalInstitution>().Where(s => s.Id == source.Id).FirstOrDefault(); if (target == null) { CommonFunc.ThrowExceptionIfRecordNotExists(EntityNames.MedicalInstitution, source.Id, OperateType.Update, _logger); } else if (!Enumerable.SequenceEqual(source.Version, target.Version)) { var modifiedUser = GetEmployeeDetail(target.LastUpdateUserId); CommonFunc.ThrowExceptionIfRecordHasBeenModified(EntityNames.MedicalInstitution, source.Id, modifiedUser.EmName, target.LastUpdateTime, OperateType.Update, _logger); } Mapper.Map(source, target); } _dbContext.SaveChanges(); return(GetMedicalInstitutionDetail(source.Id)); }