Beispiel #1
0
        public int nombreJoueurEquipe(Guid equipeId, DateTime date)
        {
            int count = 0;

            try
            {
                List <FifaModeles.TransfertsModele> lTransferts = this.ListAll();

                foreach (FifaModeles.TransfertsModele transfert in lTransferts)
                {
                    if (transfert.equipeId == equipeId && (transfert.dateDebut <= date) && ((transfert.dateFin == null) || (transfert.dateFin >= date)))
                    {
                        count++;
                    }
                }

                return(count);
            }

            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        //lance la procédure stockée avec lecture pStoredName et renvoie un DataSet avec une table du nom newTableName
        public DataSet Load(string pStoredName, string newTableName)
        {
            try
            {
                using (SqlConnection con = new SqlConnection())
                {
                    con.ConnectionString = _Connection;
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        SqlDataAdapter adapter = new SqlDataAdapter();

                        cmd.Connection  = con;
                        cmd.CommandText = ROLE + pStoredName;
                        cmd.CommandType = CommandType.StoredProcedure;

                        adapter.SelectCommand = cmd;

                        DataSet data = new DataSet();
                        adapter.Fill(data, newTableName);
                        return(data);
                    }
                }
            }

            catch (SqlException exsql)
            {
                TechnicalError oErreur = new TechnicalError(exsql);
                throw oErreur;
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
        public List <FifaModeles.CartonsRougesModele> ListAll()
        {
            List <FifaModeles.CartonsRougesModele> lcr = new List <FifaModeles.CartonsRougesModele>();

            using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
            {
                try
                {
                    foreach (CartonsRouges_GetAll_Result oCarte in ctx.CartonsRouges_GetAll())
                    {
                        FifaModeles.CartonsRougesModele cr = new FifaModeles.CartonsRougesModele();
                        cr.carteRougeId = oCarte.carteRougeId;
                        cr.joueurId     = oCarte.joueurId;
                        cr.nombreSuspensionsRestantes = oCarte.nombreSuspensionsRestantes;
                        cr.matchId     = oCarte.matchId;
                        cr.minuteRecue = oCarte.minuteRecue;
                        cr.equipeId    = oCarte.equipeId;
                        lcr.Add(cr);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is SqlException)
                    {
                        TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                        throw oErreur;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            return(lcr);
        }
        public Boolean checkPasDansQuarter(DateTime date)
        {
            try
            {
                // obtient la liste des quarters
                List <FifaModeles.QuartersModele> lQuarters = this.ListAll();

                foreach (FifaModeles.QuartersModele quarter in lQuarters)
                {
                    if (date <= quarter.dateFin && date >= quarter.dateDebut)
                    {
                        // retourne un BusinessError si on trouve un quarter dans lequel la date se trouve
                        BusinessError bErreur = new BusinessError("La date encodée est dans un quarter");
                        throw bErreur;
                    }
                }
                // si il n'a trouvé de quarter qui corresponde renvoie true
                return(true);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #5
0
        public List <FifaModeles.TransfertsModele> ListAllWithEquipeJoueurs()
        {
            try
            {
                List <FifaModeles.TransfertsModele> lJoueursTransferts;

                // donne la liste des transfert avec entités joueurs et équipes pour lesquels il n'y pas eu de sortie (participation en cours)
                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    /*
                     * lJoueursTransferts = ctx.Transferts.Include("Equipes")
                     *                                 .Include("Joueurs")
                     *                                 .Where(xx => xx.dateFin.HasValue == false)
                     *                                 .ToList();
                     */
                    lJoueursTransferts = this.ListAll().Where(xx => xx.dateFin.HasValue == false).ToList();
                }
                return(lJoueursTransferts);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #6
0
        public List <FifaModeles.TransfertsModele> ListAll()
        {
            try
            {
                List <FifaModeles.TransfertsModele> lTransferts = new List <FifaModeles.TransfertsModele>();

                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    foreach (Transferts_GetAll_Result oTrans in ctx.Transferts_GetAll())
                    {
                        FifaModeles.TransfertsModele transfert = new FifaModeles.TransfertsModele();
                        transfert.joueurId   = oTrans.joueurId;
                        transfert.equipeId   = oTrans.equipeId;
                        transfert.dateDebut  = oTrans.dateDebut;
                        transfert.dateFin    = oTrans.dateFin;
                        transfert.lastUpdate = oTrans.lastUpdate;
                        lTransferts.Add(transfert);
                    }
                }
                return(lTransferts);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #7
0
        // à partir d'une liste de nom, renvoie la liste d'équipe qui correspond
        public List <FifaModeles.EquipesModele> ListeEquipeParticipants(List <string> lNomEquipes)
        {
            try
            {
                List <FifaModeles.EquipesModele> lEquipe = new List <FifaModeles.EquipesModele>();

                foreach (string str in lNomEquipes)
                {
                    // vérifie que l'équipe existe bien
                    if (this.ListAll().Where(x => x.nom == str).FirstOrDefault() != null)
                    {
                        lEquipe.Add(this.ListAll().Where(x => x.nom == str).FirstOrDefault());
                    }
                }

                return(lEquipe);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public List <FifaModeles.EquipesParticipationModele> ListAll()
        {
            try
            {
                List <FifaModeles.EquipesParticipationModele> lEquParti = new List <FifaModeles.EquipesParticipationModele>();

                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    foreach (EquipeParticipation_GetAll_Result equipe in ctx.EquipeParticipation_GetAll())
                    {
                        FifaModeles.EquipesParticipationModele ep = new FifaModeles.EquipesParticipationModele();
                        ep.equipeId      = equipe.equipeId;
                        ep.championnatId = equipe.championnatId;
                        ep.lastUpdate    = equipe.lastUpdate;
                        lEquParti.Add(ep);
                    }
                }
                return(lEquParti);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public void enregistrerEquipesParticipation(List <FifaModeles.EquipesModele> lEquipe, Guid championnatId)
        {
            using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
            {
                try
                {
                    foreach (FifaModeles.EquipesModele equipe in lEquipe)
                    {
                        ctx.EquipeParticipation_Add(equipe.equipeId, championnatId);
                    }

                    using (TransactionScope scope = new TransactionScope())
                    {
                        ctx.SaveChanges();
                        scope.Complete();
                    }
                }

                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is SqlException)
                    {
                        TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                        throw oErreur;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
        //vérifie si il y n'a pas eu un transfert encodé d'un joueur lors de la saison avant la création de la participation de l'équipe
        public Boolean checkPasTransfertAvantParticipation(List <EquipesModele> lEquipes, int annee)
        {
            try
            {
                //récupère la liste des transferts
                TransfertsService ts = new TransfertsService();
                List <FifaModeles.TransfertsModele> lTransferts = ts.ListAll();

                foreach (FifaModeles.TransfertsModele transfert in lTransferts)
                {
                    //vérfie pour chaque transfert si il y a eu déjà un transfert pour l'équipe l'année du championnat en création ou renvoie une businessError
                    if ((transfert.dateDebut.Year == annee || (transfert.dateFin.HasValue && transfert.dateFin.Value.Year == annee)) && (lEquipes.Any(x => x.equipeId == transfert.equipeId)))
                    {
                        BusinessError oBusiness = new BusinessError("Il y a déjà eu des transferts de joueurs enregistrés cette année, l'équipe ne peut pas être inscrite dans le championnat");
                        throw oBusiness;
                    }
                }

                return(true);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public Boolean checkPasDansIntersaison(DateTime date)
        {
            try
            {
                // obtient la liste des intersaisons
                List <FifaModeles.IntersaisonsModele> lIntersaison = this.ListAll();

                foreach (FifaModeles.IntersaisonsModele intersaison in lIntersaison)
                {
                    if (date <= intersaison.dateFin && date >= intersaison.dateDebut)
                    {
                        // retourne false si la date est dans une intersaison
                        return(false);
                    }
                }
                // si il n'a trouvé d'intersaison qui corresponde renvoie true
                return(true);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #12
0
        //renvoie la liste des matchs d'une liste d'équipe du 1er janvier année de la date à la date comprise
        public List <FifaModeles.MatchsModele> ListesMatchsListeEquipeDatee(List <FifaModeles.EquipesModele> lEquipe, DateTime date)
        {
            DateTime dateDebut = new DateTime(date.Year, 1, 1);

            List <FifaModeles.MatchsModele> lMatchs = new List <FifaModeles.MatchsModele>();

            try
            {
                foreach (FifaModeles.MatchsModele match in this.ListAll())
                {
                    foreach (FifaModeles.EquipesModele equipe in lEquipe)
                    {
                        if ((match.equipe1Id == equipe.equipeId || match.equipe2Id == equipe.equipeId) && match.matchDate >= dateDebut && match.matchDate <= date)
                        {
                            lMatchs.Add(match);
                        }
                    }
                }
                return(lMatchs);
            }

            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #13
0
        public List <FifaModeles.ChampionnatsModele> ListAll()
        {
            List <FifaModeles.ChampionnatsModele> lch = new List <FifaModeles.ChampionnatsModele>();

            using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
            {
                try
                {
                    foreach (Championnats_GetAll_Result champ in ctx.Championnats_GetAll())
                    {
                        FifaModeles.ChampionnatsModele ch = new FifaModeles.ChampionnatsModele();
                        ch.championnatId = champ.championnatId;
                        ch.annee         = champ.annee;
                        ch.lastUpdate    = champ.lastUpdate;
                        lch.Add(ch);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is SqlException)
                    {
                        TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                        throw oErreur;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            return(lch);
        }
        //lance la procédure stockée sans lecture pStoredName avec la liste de paramètres lstParam et renvoie un int
        public int Execute(string pStoredName, List <SqlParameter> lstParam)
        {
            try
            {
                using (SqlConnection con = new SqlConnection())
                {
                    con.ConnectionString = _Connection;
                    using (SqlCommand cmd = new SqlCommand())
                    {
                        cmd.Connection  = con;
                        cmd.CommandText = ROLE + pStoredName;
                        cmd.CommandType = CommandType.StoredProcedure;

                        foreach (SqlParameter oParam in lstParam)
                        {
                            cmd.Parameters.Add(oParam);
                        }
                        cmd.Connection.Open();
                        return(cmd.ExecuteNonQuery());
                    }
                }
            }
            catch (SqlException exsql)
            {
                TechnicalError oErreur = new TechnicalError(exsql);
                throw oErreur;
            }

            catch (Exception ex)
            {
                throw ex;
            }
        }
Beispiel #15
0
        public List <FifaModeles.EquipesModele> ListAll()
        {
            try
            {
                List <FifaModeles.EquipesModele> lEqu = new List <FifaModeles.EquipesModele>();

                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    foreach (Equipes_GetAll_Result equipe in ctx.Equipes_GetAll())
                    {
                        FifaModeles.EquipesModele eq = new FifaModeles.EquipesModele();
                        eq.equipeId   = equipe.equipeId;
                        eq.nom        = equipe.nom;
                        eq.lastUpdate = equipe.lastUpdate;
                        eq.logoPath   = equipe.logoPath;
                        lEqu.Add(eq);
                    }
                }
                return(lEqu);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        // retourne l'objet joueur qui correspond à un nom complet ou une business Error si il n'existe pas
        public FifaModeles.JoueursModele GetJoueurs(string nomCompletJoueur)
        {
            try
            {
                List <FifaModeles.JoueursModele> lJoueurs = this.ListAll();

                foreach (FifaModeles.JoueursModele joueur in lJoueurs)
                {
                    if ((joueur.prenom + " " + joueur.nom).Equals(nomCompletJoueur))
                    {
                        return(joueur);
                    }
                }

                BusinessError oErreur = new BusinessError("Ce joueur n'existe pas");
                throw oErreur;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public List <FifaModeles.JoueursModele> getListeJoueurs(List <Guid> lId)
        {
            try
            {
                List <FifaModeles.JoueursModele> lJoueurs = new List <FifaModeles.JoueursModele>();

                foreach (Guid joueur in lId)
                {
                    lJoueurs.Add(this.GetJoueurs(joueur));
                }
                return(lJoueurs);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public List <FifaModeles.JoueursModele> ListAll()
        {
            try
            {
                List <FifaModeles.JoueursModele> lJoueurs = new List <FifaModeles.JoueursModele>();

                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    foreach (Joueurs_GetAll_Result oJou in ctx.Joueurs_GetAll())
                    {
                        FifaModeles.JoueursModele joueur = new FifaModeles.JoueursModele();
                        joueur.joueurId   = oJou.joueurId;
                        joueur.nom        = oJou.nom;
                        joueur.prenom     = oJou.prenom;
                        joueur.lastUpdate = oJou.lastUpdate;
                        lJoueurs.Add(joueur);
                    }
                }
                return(lJoueurs);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public FifaModeles.JoueursModele GetJoueurs(Guid joueurId)
        {
            try
            {
                List <FifaModeles.JoueursModele> lJoueurs = this.ListAll();

                foreach (FifaModeles.JoueursModele joueur in lJoueurs)
                {
                    if (joueur.joueurId == joueurId)
                    {
                        return(joueur);
                    }
                }

                BusinessError oErreur = new BusinessError("Ce joueur n'existe pas");
                throw oErreur;
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public List <FifaModeles.IntersaisonsModele> ListAll()
        {
            try
            {
                List <FifaModeles.IntersaisonsModele> lIntersaison = new List <FifaModeles.IntersaisonsModele>();

                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    foreach (Intersaisons_GetAll_Result oInter in ctx.Intersaisons_GetAll())
                    {
                        FifaModeles.IntersaisonsModele inter = new FifaModeles.IntersaisonsModele();
                        inter.intersaisonID = oInter.intersaisonID;
                        inter.dateDebut     = oInter.dateDebut;
                        inter.dateFin       = oInter.dateFin;
                        inter.lastUpdate    = oInter.lastUpdate;
                        inter.championnatId = oInter.championnatId;
                        lIntersaison.Add(inter);
                    }
                }
                return(lIntersaison);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public List <FifaModeles.JoueursParticipationModele> ListAll()
        {
            try
            {
                List <FifaModeles.JoueursParticipationModele> lJoueursParticipation = new List <FifaModeles.JoueursParticipationModele>();

                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    foreach (JoueursParticipation_GetAll_Result joueur in ctx.JoueursParticipation_GetAll())
                    {
                        FifaModeles.JoueursParticipationModele jpm = new FifaModeles.JoueursParticipationModele();
                        jpm.joueurId   = joueur.joueurId;
                        jpm.feuilleId  = joueur.feuilleId;
                        jpm.lastUpdate = joueur.lastUpdate;
                        lJoueursParticipation.Add(jpm);
                    }
                }
                return(lJoueursParticipation);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        public void enregistrerNewIntersaison(DateTime dateDebut, DateTime dateFin, Guid championnatId)
        {
            using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
            {
                try
                {
                    // crée une nouvelle intersaison
                    ctx.Intersaisons_Add(dateDebut, dateFin, championnatId);

                    using (TransactionScope scope = new TransactionScope())
                    {
                        ctx.SaveChanges();
                        scope.Complete();
                    }
                }

                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is SqlException)
                    {
                        TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                        throw oErreur;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }
 // renvoie true si le joueur n'a pas joué un match après la date fournie
 public Boolean checkJoueurSiPasParticipation(Guid joueurId, DateTime date)
 {
     try
     {
         int countJoueursParticipation;
         using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
         {
             countJoueursParticipation = ctx.NombreParticipationJoueurApresDate(joueurId, date);
         }
         if (countJoueursParticipation > 0)
         {
             BusinessError oBusiness = new BusinessError("Le joueur a été inscrit sur une feuille de match à une date postérieure");
             throw oBusiness;
         }
         else
         {
             return(true);
         }
     }
     catch (Exception ex)
     {
         if (ex.InnerException != null && ex.InnerException is SqlException)
         {
             TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
             throw oErreur;
         }
         else
         {
             throw ex;
         }
     }
 }
Beispiel #24
0
        public List <FifaModeles.GoalsModele> ListAll()
        {
            List <FifaModeles.GoalsModele> lGoals = new List <FifaModeles.GoalsModele>();

            using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
            {
                try
                {
                    foreach (Goals_GetAll_Result oGoal in ctx.Goals_GetAll())
                    {
                        FifaModeles.GoalsModele goal = new FifaModeles.GoalsModele();
                        goal.goalId       = oGoal.goalId;
                        goal.joueurId     = oGoal.joueurId;
                        goal.matchId      = oGoal.matchId;
                        goal.lastUpdate   = oGoal.lastUpdate;
                        goal.minuteMarque = oGoal.minuteMarque;
                        goal.equipeId     = oGoal.equipeId;
                        lGoals.Add(goal);
                    }
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is SqlException)
                    {
                        TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                        throw oErreur;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
            return(lGoals);
        }
        public List <FifaModeles.QuartersModele> ListAll()
        {
            try
            {
                List <FifaModeles.QuartersModele> lQuarters = new List <FifaModeles.QuartersModele>();

                using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                {
                    foreach (Quarters_GetAll_Result oQuart in ctx.Quarters_GetAll())
                    {
                        FifaModeles.QuartersModele quarter = new FifaModeles.QuartersModele();
                        quarter.quartersId    = oQuart.quartersId;
                        quarter.dateDebut     = oQuart.dateDebut;
                        quarter.dateFin       = oQuart.dateFin;
                        quarter.lastUpdate    = oQuart.lastUpdate;
                        quarter.championnatId = oQuart.championnatId;
                        lQuarters.Add(quarter);
                    }
                }
                return(lQuarters);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #26
0
 public override string ToString()
 {
     if (TechnicalError != null && UserFriendlyError != null && TechnicalError.Contains(UserFriendlyError))
     {
         return(TechnicalError);
     }
     return(string.Join(" ", UserFriendlyError, TechnicalError).Trim());
 }
Beispiel #27
0
        public void enregistrerTransferts(DataTable oTable)
        {
            try
            {
                if (checkTransferts(oTable))
                {
                    using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
                    {
                        //transforme la table en vue et applique un filtre pour n'avoir que les lignes modifiées
                        DataView oView = oTable.DefaultView;
                        oView.RowStateFilter = DataViewRowState.ModifiedCurrent;


                        foreach (DataRowView row in oView)
                        {
                            //récupère l'id du joueur
                            Guid     joueurId      = new JoueursService().GetJoueurs(row["Joueur :"].ToString()).joueurId;
                            DateTime dateTransfert = (DateTime)row["Date du transfert :"];

                            //mets fin au précedent transfert si il existe et rajoute un jour à la date du transfert
                            if (row["Date arrivee :"].ToString() != "" && row["Equipe :"].ToString() != "")
                            {
                                ctx.Transferts_UpdateDateFin(joueurId, (DateTime)row["Date arrivee :"], dateTransfert, DateTime.Now);

                                dateTransfert = dateTransfert.AddDays(1);
                            }

                            //crée un nouveau transfert
                            if (row["combo"].ToString() != "")
                            {
                                Guid equipeInId = new EquipesService().getEquipe(row["combo"].ToString()).equipeId;
                                ctx.Tansferts_Add(joueurId, equipeInId, dateTransfert, DateTime.Now);
                            }
                        }
                        using (TransactionScope scope = new TransactionScope())
                        {
                            ctx.SaveChanges();
                            scope.Complete();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        // vérifie si une équipe participe bien à un championnat
        public Boolean isParticipation(FifaModeles.EquipesModele equipe, DateTime date)
        {
            try
            {
                ChampionnatService cs = new ChampionnatService();
                List <FifaModeles.ChampionnatsModele> lChampionnat = cs.ListAll();

                //récupère le bon championnat
                int i = 0;
                FifaModeles.ChampionnatsModele championnat = null;
                while (i < lChampionnat.Count && championnat == null)
                {
                    if (date.Year == lChampionnat[i].annee)
                    {
                        championnat = lChampionnat[i];
                    }
                    i++;
                }

                //vérification, mais ne devrait jamais arrivé car il faut tester avant si il y a une intersaison qui existe
                if (championnat == null)
                {
                    BusinessError oBusiness = new BusinessError("Il n'y a pas de championnat à cette date");
                    throw oBusiness;
                }

                List <FifaModeles.EquipesParticipationModele> lParticipation = this.ListAll();

                //vérifie si il y a une participation de l'équipe avec le championant correspondant à la date
                foreach (FifaModeles.EquipesParticipationModele participation in lParticipation)
                {
                    if (participation.championnatId == championnat.championnatId && participation.equipeId == equipe.equipeId)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
        //vérifie si l'équipe envoyée est bien dans les 3 derniers du championnat à la date envoyée
        public Boolean isLastThree(EquipesModele equipe, DateTime date)
        {
            try
            {
                int NBEQUIPE = 3;
                EquipesParticipationService eps = new EquipesParticipationService();

                DataView oView = new GenerationTabClassementEquipe().getClassementEquipe(date).DefaultView;
                //trie le tableau de manière ascendante
                oView.Sort = "Points Totaux asc";


                //vérifie que l'équipe d'arrivée est bien dans le championnat
                if (eps.isParticipation(equipe, date))
                {
                    if (oView.Count > NBEQUIPE)
                    {
                        for (int i = 0; i < NBEQUIPE; i++)
                        {
                            //vérifie si l'équipe est dans les 3 dernières row du tableau
                            if (oView[i]["Equipe :"].ToString() == equipe.nom)
                            {
                                return(true);
                            }
                        }
                        // retourne un BusinessError si l'équipe n'est pas dans les NBEQUIPE derniers
                        BusinessError bErreur = new BusinessError("L'équipe d'arrivée (" + equipe.nom + ") n'est pas classée dans les " + NBEQUIPE + " dernières équipes du classement");
                        throw bErreur;
                    }
                    else
                    {
                        return(true);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null && ex.InnerException is SqlException)
                {
                    TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                    throw oErreur;
                }
                else
                {
                    throw ex;
                }
            }
        }
Beispiel #30
0
        //renvoie true si il a pu créer le championnat et en out le guid de ce nouveau championnat
        public Boolean enregistrerNewChampionnat(int annee, out Guid championnatId)
        {
            Boolean _return = false;

            championnatId = Guid.Empty;

            using (FifaManagerEphecEntities ctx = new FifaManagerEphecEntities(_Connection))
            {
                try
                {
                    //vérifie si un championnat existe déjà pour l'année annee et la crée si non.
                    if (this.ListAll().Where(x => x.annee == annee).FirstOrDefault() == null)
                    {
                        ctx.Championnats_Add(annee);

                        using (TransactionScope scope = new TransactionScope())
                        {
                            ctx.SaveChanges();
                            championnatId = this.getChampionnat(annee).championnatId;
                            scope.Complete();
                        }

                        _return = true;
                    }
                    if (!_return)
                    {
                        BusinessError oErreur = new BusinessError("Ce championnat existe déjà");
                        throw oErreur;
                    }
                    return(_return);
                }
                catch (Exception ex)
                {
                    if (ex.InnerException != null && ex.InnerException is SqlException)
                    {
                        TechnicalError oErreur = new TechnicalError((SqlException)ex.InnerException);
                        throw oErreur;
                    }
                    else
                    {
                        throw ex;
                    }
                }
            }
        }