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:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
searchRequest | B2BVotantSearchRequest? | 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:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
identifiant | string | Identifiant 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:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
dto | B2BUpsertVotantDto | Donné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:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
identifiant | string | Identifiant externe du votant |
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:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
identifiant | string | Identifiant 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
| Action | Effet | Réversible | Votant visible |
|---|---|---|---|
| Supprimer | Retrait complet | Non | Non |
| Radier | Perte du droit de vote | Oui (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
B2BVotantItem- Informations d'un votantB2BUpsertVotantDto- DTO pour création/modificationB2BVotantSearchRequest- Paramètres de recherche