public DataResult <UserInfoModel> RegenerateVerificationCode(int userId) { try { var generateCodeRetries = 0; while (generateCodeRetries <= m_codeGeneratorConfiguration.MaxGenerateVerificationCodeRetries) { var newVerificationCode = m_codeGeneratorManager.GenerateVerificationCode(); var verificationCodeCreateTime = DateTime.UtcNow; try { var entity = m_userUoW.UpdateVerificationCode(userId, newVerificationCode, verificationCodeCreateTime); var result = m_mapper.Map <UserInfoModel>(entity); return(Success(result)); } catch (VerficationCodeAlreadyExistsException e) { m_logger.LogWarning(e); generateCodeRetries++; } } m_logger.LogWarning("Generating verification code failed for user with id '{0}' with {1} retries", userId, m_codeGeneratorConfiguration.MaxGenerateVerificationCodeRetries); return(Error <UserInfoModel>(m_translator.Translate("generate-verification-code-failed"), DataResultErrorCode.GenerateVerificationCode)); } catch (NoResultException <UserEntity> e) { m_logger.LogWarning(e); return(Error <UserInfoModel>(m_translator.Translate("invalid-user-id"), DataResultErrorCode.UserNotExistId)); } catch (DatabaseException e) { m_logger.LogWarning(e); return(Error <UserInfoModel>(e.Message)); } }