public IEnumerable <IEvénementMétier> FaireUnRetrait(Montant montantRetrait, DateTime dateRetrait) { var numeroDeCompte = RecupererNumeroDeCompte(); if (numeroDeCompte == string.Empty) { return(null); } var retrait = new RetraitRéalisé(numeroDeCompte, montantRetrait, dateRetrait); var montantRestantSurLeCompte = CalculerMontantRestantSurLeCompteApresRetrait(retrait); if (montantRestantSurLeCompte >= 0) { return(new[] { (IEvénementMétier)retrait }); } if (Math.Abs(montantRestantSurLeCompte) > RecupererAutorisationDeCredit()) { throw new RetraitNonAutorisé(); } var balanceNegative = new BalanceNégativeDétectée(numeroDeCompte, new Montant(Math.Abs(montantRestantSurLeCompte)), dateRetrait); return(new[] { (IEvénementMétier)retrait, balanceNegative }); }
private int CalculerMontantRestantSurLeCompteApresRetrait(RetraitRéalisé retraitRealise) { var listeDebitsEtCredits = _evenementsMetiers.Where(e => e is RetraitRéalisé || e is DépotRéalisé); var soldeCompte = 0; foreach (var debitCredit in listeDebitsEtCredits) { if (debitCredit is DépotRéalisé) { soldeCompte += ((DépotRéalisé)debitCredit).MontantDepot.ValeurMontant; } else { soldeCompte -= ((RetraitRéalisé)debitCredit).MontantRetrait.ValeurMontant; } } return soldeCompte - retraitRealise.MontantRetrait.ValeurMontant; }
private int CalculerMontantRestantSurLeCompteApresRetrait(RetraitRéalisé retraitRealise) { var listeDebitsEtCredits = _evenementsMetiers.Where(e => e is RetraitRéalisé || e is DépotRéalisé); var soldeCompte = 0; foreach (var debitCredit in listeDebitsEtCredits) { if (debitCredit is DépotRéalisé) { soldeCompte += ((DépotRéalisé)debitCredit).MontantDepot.ValeurMontant; } else { soldeCompte -= ((RetraitRéalisé)debitCredit).MontantRetrait.ValeurMontant; } } return(soldeCompte - retraitRealise.MontantRetrait.ValeurMontant); }
public IEnumerable<IEvénementMétier> FaireUnRetrait(Montant montantRetrait, DateTime dateRetrait) { var numeroDeCompte = RecupererNumeroDeCompte(); if (numeroDeCompte == string.Empty) { return null; } var retrait = new RetraitRéalisé(numeroDeCompte, montantRetrait, dateRetrait); var montantRestantSurLeCompte = CalculerMontantRestantSurLeCompteApresRetrait(retrait); if (montantRestantSurLeCompte >= 0) { return new[] { (IEvénementMétier)retrait }; } if (Math.Abs(montantRestantSurLeCompte) > RecupererAutorisationDeCredit()) { throw new RetraitNonAutorisé(); } var balanceNegative = new BalanceNégativeDétectée(numeroDeCompte, new Montant(Math.Abs(montantRestantSurLeCompte)), dateRetrait); return new[] { (IEvénementMétier)retrait, balanceNegative }; }