public async Task <Result> HandleAsync(PersonneAjoutee domainEvent, IEventContext context = null) { var famille = await _familleRepository.GetFamilleByNomAsync(domainEvent.NomFamille); if (famille != null) { famille.Personnes.Add(new Data.Models.Personne { DateNaissance = domainEvent.DateNaissance, LieuNaissance = domainEvent.LieuNaissance, Prenom = domainEvent.Prenom }); await _familleRepository.SauverFamilleAsync(famille); } var color = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine($"{domainEvent.Prenom} a correctement été ajouté(e) à la famille {domainEvent.NomFamille.Value}."); Console.ForegroundColor = color; return(Result.Ok()); }
public async Task <Result> HandleAsync(FamilleCreee domainEvent, IEventContext context = null) { var color = Console.ForegroundColor; try { await _familleRepository.SauverFamilleAsync(new Data.Models.Famille { Nom = domainEvent.NomFamille.Value }).ConfigureAwait(false); Console.ForegroundColor = ConsoleColor.DarkGreen; Console.WriteLine($"La famille {domainEvent.NomFamille.Value} a correctement" + $" été créée dans le système."); } catch (Exception e) { Console.ForegroundColor = ConsoleColor.DarkRed; Console.WriteLine($"La famille {domainEvent.NomFamille.Value} n'a pas pu être" + $" créée dans le système."); Console.WriteLine(e.ToString()); return(Result.Fail()); } finally { Console.ForegroundColor = color; } return(Result.Ok()); }