/// <summary> /// Controleert een aantal parameters en bepaalt op basis van de score of het adres verdacht is. /// Verdacht betekent: de kans is groot dat het niet om een eigen adres gaat of dat het fout geschreven is. /// </summary> /// <param name="communicatieVorm">Het mailadres dat we gaan controleren</param> /// <returns><c>True</c> als het waarschijnlijk niet om een eigen mailadres gaat of fout geschreven is, /// <c>false</c> als de kans groot is dat het wel in orde is.</returns> public bool IsVerdacht(CommunicatieVorm communicatieVorm) { // Controleren of het adres (nog) verdacht is if (communicatieVorm.GelieerdePersoon.Persoon.GeboorteDatum.HasValue && (DateTime.Now.Year - communicatieVorm.GelieerdePersoon.Persoon.GeboorteDatum.Value.Year) > Settings.Default.Ketileeftijd && communicatieVorm.IsGezinsgebonden) { // Vanaf de keti's moet je een eigen mailadres als voorkeursadres hebben, en de groep heeft hun eigen gsm-nr nodig return(true); } else { if (communicatieVorm.CommunicatieType.ID == (int)CommunicatieTypeEnum.Email) { if (communicatieVorm.GelieerdePersoon.Persoon.GeboorteDatum.HasValue) { return(_mailadresCtrl.MailadresIsVerdacht(communicatieVorm.GelieerdePersoon.Persoon.VoorNaam, communicatieVorm.GelieerdePersoon.Persoon.Naam, communicatieVorm.GelieerdePersoon.Persoon.GeboorteDatum.Value.Year, communicatieVorm.Nummer)); } else { return(_mailadresCtrl.MailadresIsVerdacht(communicatieVorm.GelieerdePersoon.Persoon.VoorNaam, communicatieVorm.GelieerdePersoon.Persoon.Naam, communicatieVorm.Nummer)); } } else { // Geen e-mail, dus moeilijk te controleren. Dan geven we het voordeel van de twijfel. return(false); } } }
/// <summary> /// Werkt de gegeven <paramref name="communicatieVorm"/> bij op basis van de informatie /// in <paramref name="communicatieInfo"/>. /// </summary> /// <param name="communicatieVorm">Bij te werken communicatievorm</param> /// <param name="communicatieInfo">Nieuwe informatie communicatievorm</param> public void Bijwerken(CommunicatieVorm communicatieVorm, CommunicatieInfo communicatieInfo) { // Entity framework zal zelf nakijken of er een ID wordt overschreven, en of er geen concurrency- // problemen optraden. Daar trekken we ons niets van aan. if (communicatieVorm.CommunicatieType.ID != communicatieInfo.CommunicatieTypeID) { // Wisselen van communicatietypes ondersteunen we momenteel niet throw new NotSupportedException(); } if (!IsGeldig(communicatieInfo.Nummer, communicatieVorm.CommunicatieType)) { throw new FoutNummerException(FoutNummer.ValidatieFout, string.Format(Resources.CommunicatieVormValidatieFeedback, communicatieInfo.Nummer, communicatieVorm.CommunicatieType.Omschrijving)); } // Voor de rest kopieer ik gewoon velden van communicatieInfo naar communicatieVorm. Ik gebruik hier // geen automapper, om te vermijden dat er onverwachte zaken worden overschreven. Bovendien is // het stuk 'voorkeur' speciaal. communicatieVorm.IsGezinsgebonden = communicatieInfo.IsGezinsGebonden; communicatieVorm.Nota = communicatieInfo.Nota; communicatieVorm.Nummer = communicatieInfo.Nummer; communicatieVorm.VersieString = communicatieInfo.VersieString; communicatieVorm.IsVerdacht = IsVerdacht(communicatieVorm); communicatieVorm.LaatsteControle = DateTime.Now; if (communicatieInfo.Voorkeur) { VoorkeurZetten(communicatieVorm); } }
/// <summary> /// Stelt de gegeven communicatievorm in als voorkeurscommunicatievorm voor zijn /// type en gelieerde persoon /// </summary> /// <param name="cv"> /// Communicatievorm die voorkeurscommunicatievorm moet worden, /// gegeven zijn type en gelieerde persoon /// </param> public void VoorkeurZetten(CommunicatieVorm cv) { foreach ( var communicatieVorm in cv.GelieerdePersoon.Communicatie.Where(c => c.CommunicatieType.ID == cv.CommunicatieType.ID).ToArray ()) { communicatieVorm.Voorkeur = Equals(communicatieVorm, cv); } }
public void KoppelenVoorkeursCommunicatieTest() { // Arrange const int TESTGPID = 1234; // arbitrair ID van een gelieerde persoon const int TESTCVID = 2345; // en van een communicatievorm const int TESTCTID = 3; // en diens communicatietype var testCommunicatieType = new CommunicatieType { ID = TESTCTID, Validatie = ".*" }; var testCommunicatieVorm = new CommunicatieVorm { ID = TESTCVID, CommunicatieType = testCommunicatieType, Nummer = "*****@*****.**", Voorkeur = true }; // Koppel gauw testCommunicatieVorm aan testGelieerdePersoon var testGelieerdePersoon = new GelieerdePersoon { ID = TESTGPID, Persoon = new Persoon(), Communicatie = new EntityCollection <CommunicatieVorm> { testCommunicatieVorm } }; testCommunicatieVorm.GelieerdePersoon = testGelieerdePersoon; var target = Factory.Maak <CommunicatieVormenManager>(); CommunicatieVorm nieuwecv = new CommunicatieVorm { CommunicatieType = testCommunicatieType, // e-mail ID = 0, // nieuwe communicatievorm Nummer = "*****@*****.**", // arbitrair nieuw e-mailadres Voorkeur = true }; // act target.Koppelen(testGelieerdePersoon, nieuwecv); // assert Assert.IsFalse(testCommunicatieVorm.Voorkeur); }
public CommunicatieVorm Kloon(CommunicatieVorm cv) { var kloon = new CommunicatieVorm { Nota = cv.Nota, Nummer = cv.Nummer, IsGezinsgebonden = cv.IsGezinsgebonden, Voorkeur = cv.Voorkeur, GelieerdePersoon = cv.GelieerdePersoon, CommunicatieType = cv.CommunicatieType }; return(kloon); }
/// <summary> /// Verwijdert een communicatievorm uit Kipadmin /// </summary> /// <param name="communicatieVorm">Te verwijderen communicatievorm, gekoppeld aan een gelieerde persoon /// met ad-nummer.</param> public void Verwijderen(CommunicatieVorm communicatieVorm) { Debug.Assert(communicatieVorm.GelieerdePersoon != null); Debug.Assert(communicatieVorm.GelieerdePersoon.Persoon != null); Debug.Assert(communicatieVorm.GelieerdePersoon.Persoon.InSync); ServiceHelper.CallService <ISyncPersoonService>( svc => svc.CommunicatieVerwijderen( MappingHelper.Map <Persoon, Kip.ServiceContracts.DataContracts.Persoon>(communicatieVorm.GelieerdePersoon.Persoon), new CommunicatieMiddel { Type = (CommunicatieType)communicatieVorm.CommunicatieType.ID, Waarde = communicatieVorm.Nummer })); }
/// <summary> /// Stuurt de gegeven <paramref name="communicatieVorm"/> naar Kipadmin. Om te weten welk de /// originele communicatievorm is, kijken we naar de gekoppelde persoon, en gebruiken we /// het oorspronkelijke nummer (<paramref name="origineelNummer"/>) /// </summary> /// <param name="communicatieVorm">Te updaten communicatievorm</param> /// <param name="origineelNummer">Oorspronkelijk nummer van die communicatievorm</param> /// <remarks>Het is best mogelijk dat het 'nummer' niet is veranderd, maar bijv. enkel de vlag /// 'opt-in'</remarks> public void Bijwerken(CommunicatieVorm communicatieVorm, string origineelNummer) { Debug.Assert(communicatieVorm.GelieerdePersoon != null); Debug.Assert(communicatieVorm.GelieerdePersoon.Persoon != null); Debug.Assert(communicatieVorm.GelieerdePersoon.Persoon.InSync); ServiceHelper.CallService <ISyncPersoonService>( svc => svc.CommunicatieBijwerken( MappingHelper.Map <Persoon, Kip.ServiceContracts.DataContracts.Persoon>( communicatieVorm.GelieerdePersoon.Persoon), origineelNummer, new CommunicatieMiddel { Type = (CommunicatieType)communicatieVorm.CommunicatieType.ID, Waarde = communicatieVorm.Nummer, IsBulk = communicatieVorm.Voorkeur })); }
public void TestOngeldigTelefoonnummerValideren() { // Arrange var cvValid = new CommunicatieVormValidator(); var comm = new CommunicatieVorm { CommunicatieType = new CommunicatieType { ID = (int)CommunicatieTypeEnum.TelefoonNummer, Validatie = @"^0[0-9]{1,2}\-[0-9]{2,3} ?[0-9]{2} ?[0-9]{2}$|^04[0-9]{2}\-[0-9]{2,3} ?[0-9]{2} ?[0-9]{2}$|^[+][0-9]*$" }, Nummer = "03/231.07.95" }; // Act bool vlag = cvValid.Valideer(comm); // Assert Assert.IsFalse(vlag); }
public bool IsGav(CommunicatieVorm communicatieVorm) { return(true); }
public void CommunicatieVormVoorkeurMakenTest() { // Vroeger testten we of de andere communicatie wel degelijk gepersisteerd // werd. Vooral omdat we dat toen zelf moesten implementeren. Nu wordt // bewaard met 'Context.SaveChanges'. Ik vermoed niet dat we EntityFramework // moeten debuggen, dus ik paste deze test aan, zodat die gewoon nakijkt // of // Arrange const int TESTGPID = 1234; // arbitrair ID van een gelieerde persoon const int TESTCVID = 2345; // en van een communicatievorm const int TESTCVID2 = 2346; // en van een andere communicatievorm const int TESTCTID = 3; // en hun communicatietype var testCommunicatieType = new CommunicatieType { ID = TESTCTID, Validatie = ".*" }; var testGelieerdePersoon = new GelieerdePersoon { ID = TESTGPID, Persoon = new Persoon() }; var testCommunicatieVorm1 = new CommunicatieVorm { ID = TESTCVID, CommunicatieType = testCommunicatieType, Nummer = "*****@*****.**", Voorkeur = true, GelieerdePersoon = testGelieerdePersoon }; var testCommunicatieVorm2 = new CommunicatieVorm { ID = TESTCVID2, CommunicatieType = testCommunicatieType, Nummer = "*****@*****.**", Voorkeur = false, GelieerdePersoon = testGelieerdePersoon }; testGelieerdePersoon.Communicatie = new[] { testCommunicatieVorm1, testCommunicatieVorm2 }; var info = new CommunicatieInfo { CommunicatieTypeID = TESTCTID, // ID testcommunicatietype ID = TESTCVID2, // ID niet-voorkeurscommunicatie Nummer = "*****@*****.**", // arbitrair nieuw e-mailadres Voorkeur = true // nu wel voorkeur }; var target = Factory.Maak <CommunicatieVormenManager>(); // Act target.Bijwerken(testCommunicatieVorm2, info); // Assert // We hebben communicatievorm2 aangepast, maar omdat die de voorkeur // krijgt, moet communicatievorm1 zijn voorkeur verliezen. Assert.IsFalse(testCommunicatieVorm1.Voorkeur); }
public bool IsGav(CommunicatieVorm communicatieVorm) { throw new NotImplementedException(); }
/// <summary> /// Koppelt een communicatievorm aan een gelieerde persoon. /// </summary> /// <param name="gelieerdePersoon"> /// De gelieerde persoon voor wie de communicatievorm toegevoegd of aangepast wordt /// </param> /// <param name="nieuweCommunicatieVorm"> /// De nieuwe gegevens voor de communicatievorm /// </param> /// <returns> /// De lijst van effectief gekoppelde communicatievormen. Als <paramref name="nieuweCommunicatieVorm"/> /// gezinsgebonden is, kunnen dat er meer zijn. /// </returns> /// <remarks> /// Als de communicatievorm de eerste van een bepaald type is, dan wordt dat ook de voorkeur. /// </remarks> public List <CommunicatieVorm> Koppelen(GelieerdePersoon gelieerdePersoon, CommunicatieVorm nieuweCommunicatieVorm) { // Opmerking: gebruik dit niet als referentie-implementatie: // Te veel rommel! var gekoppeld = new List <CommunicatieVorm>(); var cvValid = new CommunicatieVormValidator(); if (!cvValid.Valideer(nieuweCommunicatieVorm)) { throw new FoutNummerException(FoutNummer.ValidatieFout, string.Format(Resources.CommunicatieVormValidatieFeedback, nieuweCommunicatieVorm.Nummer, nieuweCommunicatieVorm.CommunicatieType.Omschrijving)); } // nieuweCommunicatieVorm kan hier nog geen ID hebben Debug.Assert(nieuweCommunicatieVorm.ID == 0); nieuweCommunicatieVorm.GelieerdePersoon = gelieerdePersoon; gelieerdePersoon.Communicatie.Add(nieuweCommunicatieVorm); gekoppeld.Add(nieuweCommunicatieVorm); if (nieuweCommunicatieVorm.IsGezinsgebonden) { // Beetje gepruts voor gezinsgebonden communicatie. Dit zit niet juist op database-niveau. (#1070) // Als er gezinsgebonden communicatie wordt toegevoegd, dan voegen we die hier toe aan alle andere // gezinsleden, of juister: adresgenoten. var alleAdresgenoten = gelieerdePersoon.Persoon.PersoonsAdres.Select(pa => pa.Adres) .SelectMany(adr => adr.PersoonsAdres) .Select(pa => pa.Persoon).ToList(); var mijnAdresGenoten = _autorisatieMgr.MijnGelieerdePersonen(alleAdresgenoten); // adresgenoten die ik niet zelf ben, en die het e-mailadres nog niet hebben. var relevanteAdresGenoten = (from gp in mijnAdresGenoten where gp.ID != gelieerdePersoon.ID && !gp.Communicatie.Any( cv => cv.CommunicatieType.ID == nieuweCommunicatieVorm.CommunicatieType.ID && String.Compare(cv.Nummer, nieuweCommunicatieVorm.Nummer, StringComparison.OrdinalIgnoreCase) == 0) select gp).ToList(); foreach (var adresgenoot in relevanteAdresGenoten) { var cvKloon = Kloon(nieuweCommunicatieVorm); cvKloon.GelieerdePersoon = adresgenoot; adresgenoot.Communicatie.Add(cvKloon); gekoppeld.Add(cvKloon); } } // Voorkeurscommunicatie zetten voor toegevoegde communicatievorm. // Opgelet: als de communicatievorm gezinsgebonden was, en voorkeur, dan zal die // bij de gezinsgenoten die hem nog niet hebben als voorkeurscommunicatie van dat // type toegevoegd worden. Dit is misschien gewenst, misschien ook niet. Maar // alleszins erg verwarrend. Zie ook #1070. foreach (var cv in gekoppeld) { bool eersteVanType = (from c in cv.GelieerdePersoon.Communicatie where c.CommunicatieType.ID == nieuweCommunicatieVorm.CommunicatieType.ID && !Equals(c, cv) select c).FirstOrDefault() == null; if (eersteVanType || cv.Voorkeur) { VoorkeurZetten(nieuweCommunicatieVorm); } } return(gekoppeld); }
public bool IsGav(CommunicatieVorm communicatieVorm) { return(IsGav(communicatieVorm.GelieerdePersoon.Groep)); }
public void Bijwerken(CommunicatieVorm communicatieVorm, string origineelNummer) { }
public void Toevoegen(CommunicatieVorm commvorm) { }
public void Verwijderen(CommunicatieVorm communicatieVorm) { }