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);
GetVotantById
Récupère un votant par son identifiant MCM (Guid).
Task<ErrorOr<B2BVotantItem>> GetVotantById(Guid campagneId, Guid votantId)
Paramètres:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
votantId | Guid | Identifiant interne MCM du votant |
Retour: Informations complètes du votant.
Exemple:
var votantId = Guid.Parse("550e8400-e29b-41d4-a716-446655440000");
var result = await _votantsClient.GetVotantById(campagneId, votantId);
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. Pour une création, omettre VotantId. Pour une mise à jour, fournir le VotantId retourné lors de la création.
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 MCM (Guid) du votant créé ou mis à jour.
Exemple — Création:
var dto = new B2BUpsertVotantDto
{
// VotantId omis → création
Identifiant = "EMP-12345", // Métadonnée optionnelle
Courriel = "jean.dupont@example.com",
CourrielAlternatif = "jean.d@gmail.com",
Nom = "Dupont",
Prenom = "Jean",
DroitDeVote = true,
Poids = 1.0m,
Commentaire = "Admis le 2026-01-15" // Optionnel
};
var result = await _votantsClient.UpsertVotant(campagneId, dto);
if (result.IsError)
{
_logger.LogError("Erreur upsert: {Error}", result.FirstError.Description);
return;
}
var votantId = result.Value; // Guid — à conserver pour les futures mises à jour
_logger.LogInformation("Votant créé: {Id}", votantId);
Exemple — Mise à jour:
var dto = new B2BUpsertVotantDto
{
VotantId = votantId, // Guid retourné lors de la création
Courriel = "jean.dupont@example.com",
Nom = "Dupont",
Prenom = "Jean",
DroitDeVote = false,
Poids = 1.0m
};
var result = await _votantsClient.UpsertVotant(campagneId, dto);
Import en lot
Pour importer plusieurs votants, utilisez une boucle avec UpsertVotant:
var votantsAImporter = new[]
{
new B2BUpsertVotantDto { Nom = "Dupont", Prenom = "Jean", Courriel = "jean@ex.com", Identifiant = "EMP-001" },
new B2BUpsertVotantDto { Nom = "Martin", Prenom = "Marie", Courriel = "marie@ex.com", Identifiant = "EMP-002" },
// ...
};
var erreurs = new List<(string Courriel, string Message)>();
foreach (var votant in votantsAImporter)
{
var result = await _votantsClient.UpsertVotant(campagneId, votant);
if (result.IsError)
{
erreurs.Add((votant.Courriel, result.FirstError.Description));
}
}
if (erreurs.Any())
{
foreach (var (courriel, message) in erreurs)
{
_logger.LogWarning("Erreur pour {Courriel}: {Message}", courriel, message);
}
}
DeleteVotant
Supprime un votant de la campagne.
Task<ErrorOr<Success>> DeleteVotant(Guid campagneId, Guid votantId)
Paramètres:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
votantId | Guid | Identifiant interne MCM du votant |
Un votant ne peut être supprimé que s'il n'a pas encore voté.
Exemple:
var result = await _votantsClient.DeleteVotant(campagneId, votantId);
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, Guid votantId)
Paramètres:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
votantId | Guid | Identifiant interne MCM du votant |
Exemple:
var result = await _votantsClient.RadierVotant(campagneId, votantId);
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.
MettreAJourDroitsDeVote
Met à jour les droits de vote en lot pour une liste de votants identifiés par leur identifiant MCM (Guid).
Task<ErrorOr<B2BMettreAJourDroitsDeVoteResult>> MettreAJourDroitsDeVote(Guid campagneId, B2BMettreAJourDroitsDeVoteDto dto)
Paramètres:
| Nom | Type | Description |
|---|---|---|
campagneId | Guid | Identifiant de la campagne |
dto | B2BMettreAJourDroitsDeVoteDto | IDs MCM des votants et valeur du droit de vote |
Retour: Résultat contenant le nombre de votants mis à jour et les IDs non trouvés.
Exemple:
var dto = new B2BMettreAJourDroitsDeVoteDto
{
VotantIds = new[]
{
Guid.Parse("550e8400-e29b-41d4-a716-446655440000"),
Guid.Parse("550e8400-e29b-41d4-a716-446655440001"),
Guid.Parse("550e8400-e29b-41d4-a716-446655440002"),
},
DroitDeVote = false, // Retirer le droit de vote
Commentaire = "Radiation suite à un départ" // Optionnel
};
var result = await _votantsClient.MettreAJourDroitsDeVote(campagneId, dto);
if (result.IsError)
{
_logger.LogError("Erreur: {Error}", result.FirstError.Description);
return;
}
_logger.LogInformation("{Count} votants mis à jour", result.Value.NombreMisAJour);
if (result.Value.VotantIdsNonTrouves.Count > 0)
{
_logger.LogWarning("IDs non trouvés: {Ids}",
string.Join(", ", result.Value.VotantIdsNonTrouves));
}
Types associés
B2BVotantItem- Informations d'un votantB2BUpsertVotantDto- DTO pour création/modificationB2BVotantSearchRequest- Paramètres de rechercheB2BMettreAJourDroitsDeVoteDto- DTO pour mise à jour en lotB2BMettreAJourDroitsDeVoteResult- Résultat de la mise à jour