/// <summary> /// Mise à jour de la date d'expiration /// dans la base des cartes encryptées par /// le FrontOffice /// </summary> /// <param name="token">Token (+ nouvelle date d'expiration)</param> public void UpdateEncryptedCard(FOTokenResult token) { string request = "UPDATE Cards SET ExpirationDate = @expirationDate WHERE Token = @token"; // objet command SqlCommand command = new SqlCommand(request, GetConnection()); try { // Préparation des variables bindées command.Parameters.Add("@expirationDate", SqlDbType.DateTime); command.Parameters.Add("@token", SqlDbType.VarChar, 50); // Affectation des variables bindées command.Parameters["@expirationDate"].Value = token.GetExpirationDate(); command.Parameters["@token"].Value = token.GetToken(); // Exécution de la requête command.ExecuteNonQuery(); // Tout s'est bien passé } catch (Exception e) { // Une exception a été levée lors de l'insertion throw new Exception(GetMessages().GetString("UpdateEncryptedCard.UpdateEncryptedCard.Error", token.GetToken(), e.Message, true)); } finally { DisposeCommand(command); } }
/// <summary> /// Récupération du token identifiant l'enregistrement /// unique dans la table à partir du numéro de carte encrypté /// </summary> /// <param name="encryptedPan">numéro de carte encrypté</param> /// <returns>token et date d'expiration</returns> public FOTokenResult GetToken(string encryptedPan) { FOTokenResult retval = new FOTokenResult(); string request = "SELECT Token, ExpirationDate FROM Cards (NOLOCK) WHERE EncryptedPAN = @encryptedPAN"; // objet command SqlCommand command = new SqlCommand(request, GetConnection()); SqlDataReader dr = null; try { // Paramètres (bind variable) command.CommandType = CommandType.Text; command.Parameters.Add("@encryptedPAN", SqlDbType.VarChar, 48); command.Parameters["@encryptedPAN"].Value = encryptedPan; dr = command.ExecuteReader(); // Normalement une seule ligne sera renvoyée if (dr.Read()) { // On a trouvé un token pour le cryptogramme retval.SetValues(dr["Token"].ToString(), Util.GetSQLDataTime(dr, "ExpirationDate")); } } catch (Exception e) { throw new Exception(GetMessages().GetString("EncryptedDB.GetToken.ErrorGettingToken", e.Message, true)); } finally { CloseDataReader(dr, command); } return(retval); }