Aller au contenu principal

IVotantsClient

Client pour la gestion des votants au sein d'une campagne de vote.

public interface IVotantsClient : IBaseClient

Méthodes

GetVotantsByCampagne

Récupère tous les votants d'une campagne avec filtres optionnels.

Task<ErrorOr<IEnumerable<B2BVotantItem>>> GetVotantsByCampagne(Guid campagneId, B2BVotantSearchRequest? searchRequest = null)

Paramètres:

NomTypeDescription
campagneIdGuidIdentifiant de la campagne
searchRequestB2BVotantSearchRequest?Filtres de recherche (optionnel)

Retour: Liste des votants correspondant aux critères.

Exemple:

// Récupérer tous les votants
var result = await _votantsClient.GetVotantsByCampagne(campagneId);

if (result.IsError)
{
_logger.LogError("Erreur: {Error}", result.FirstError.Description);
return;
}

foreach (var votant in result.Value)
{
var statut = votant.AVote ? "A voté" : "N'a pas voté";
Console.WriteLine($"{votant.Prenom} {votant.Nom} - {statut}");
}

// Avec filtres - votants qui n'ont pas encore voté
var searchRequest = new B2BVotantSearchRequest
{
AVote = false,
DroitDeVote = true
};

var nonVotants = await _votantsClient.GetVotantsByCampagne(campagneId, searchRequest);

GetVotantByIdentifiant

Récupère un votant par son identifiant externe.

Task<ErrorOr<B2BVotantItem>> GetVotantByIdentifiant(Guid campagneId, string identifiant)

Paramètres:

NomTypeDescription
campagneIdGuidIdentifiant de la campagne
identifiantstringIdentifiant externe du votant (ex: numéro d'employé)

Retour: Informations complètes du votant.

Exemple:

var result = await _votantsClient.GetVotantByIdentifiant(campagneId, "EMP-12345");

if (result.IsError)
{
if (result.FirstError.Type == ErrorType.NotFound)
{
Console.WriteLine("Votant non trouvé");
}
return;
}

var votant = result.Value;
Console.WriteLine($"Votant: {votant.Prenom} {votant.Nom}");
Console.WriteLine($"Courriel: {votant.Courriel}");
Console.WriteLine($"Poids du vote: {votant.Poids}");
Console.WriteLine($"A voté: {(votant.AVote ? "Oui" : "Non")}");

UpsertVotant

Crée ou met à jour un votant. L'identifiant externe est utilisé pour la correspondance.

Task<ErrorOr<Guid>> UpsertVotant(Guid campagneId, B2BUpsertVotantDto dto)

Paramètres:

NomTypeDescription
campagneIdGuidIdentifiant de la campagne
dtoB2BUpsertVotantDtoDonnées du votant

Retour: Identifiant du votant créé ou mis à jour.

Exemple:

var votant = new B2BUpsertVotantDto
{
Identifiant = "EMP-12345", // Clé de correspondance
Courriel = "jean.dupont@example.com",
CourrielAlternatif = "jean.d@gmail.com",
Nom = "Dupont",
Prenom = "Jean",
DroitDeVote = true,
Poids = 1.0m
};

var result = await _votantsClient.UpsertVotant(campagneId, votant);

if (result.IsError)
{
_logger.LogError("Erreur upsert: {Error}", result.FirstError.Description);
return;
}

var votantId = result.Value;
_logger.LogInformation("Votant créé/mis à jour: {Id}", votantId);

Import en lot

Pour importer plusieurs votants, utilisez une boucle avec UpsertVotant:

var votantsAImporter = new[]
{
new B2BUpsertVotantDto { Identifiant = "EMP-001", Nom = "Dupont", Prenom = "Jean", Courriel = "jean@ex.com" },
new B2BUpsertVotantDto { Identifiant = "EMP-002", Nom = "Martin", Prenom = "Marie", Courriel = "marie@ex.com" },
// ...
};

var erreurs = new List<(string Id, string Message)>();

foreach (var votant in votantsAImporter)
{
var result = await _votantsClient.UpsertVotant(campagneId, votant);
if (result.IsError)
{
erreurs.Add((votant.Identifiant, result.FirstError.Description));
}
}

if (erreurs.Any())
{
foreach (var (id, message) in erreurs)
{
_logger.LogWarning("Erreur pour {Id}: {Message}", id, message);
}
}

DeleteVotant

Supprime un votant de la campagne.

Task<ErrorOr<Success>> DeleteVotant(Guid campagneId, string identifiant)

Paramètres:

NomTypeDescription
campagneIdGuidIdentifiant de la campagne
identifiantstringIdentifiant externe du votant
attention

Un votant ne peut être supprimé que s'il n'a pas encore voté.

Exemple:

var result = await _votantsClient.DeleteVotant(campagneId, "EMP-12345");

if (result.IsError)
{
_logger.LogError("Erreur suppression: {Error}", result.FirstError.Description);
return;
}

_logger.LogInformation("Votant supprimé");

RadierVotant

Radie un votant (lui retire son droit de vote sans le supprimer).

Task<ErrorOr<Success>> RadierVotant(Guid campagneId, string identifiant)

Paramètres:

NomTypeDescription
campagneIdGuidIdentifiant de la campagne
identifiantstringIdentifiant externe du votant

Exemple:

var result = await _votantsClient.RadierVotant(campagneId, "EMP-12345");

if (result.IsError)
{
_logger.LogError("Erreur radiation: {Error}", result.FirstError.Description);
return;
}

_logger.LogInformation("Votant radié - ne peut plus voter");

Différence entre suppression et radiation

ActionEffetRéversibleVotant visible
SupprimerRetrait completNonNon
RadierPerte du droit de voteOui (via Upsert)Oui (EstRadie=true)

La radiation est utile pour garder une trace des votants qui ont perdu leur droit de vote (départ, suspension, etc.) tout en conservant leur historique.

Types associés