Esempio n. 1
0
        private List <Race> BuildRaceList(DbDataReader reader)
        {
            List <Race> list = new List <Race>();

            while (reader.Read())
            {
                var raceId = reader.GetInt32(reader.GetOrdinal("CId"));

                Race r;
                if (list.All(x => x.Id != raceId))
                {
                    r = new Race
                    {
                        Id          = raceId,
                        Title       = reader.GetString(reader.GetOrdinal("CTitre")),
                        Description = reader.GetString(reader.GetOrdinal("CDescription")),
                        DateStart   = reader.GetDateTime(reader.GetOrdinal("CDateStart")),
                        DateEnd     = reader.GetDateTime(reader.GetOrdinal("CDateEnd")),
                        Town        = reader.GetString(reader.GetOrdinal("CVille")),
                        Competitors = new List <Competitor>(),
                        Organisers  = new List <Organizer>()
                    };
                    list.Add(r);
                }
                else
                {
                    r = list.Single(x => x.Id == raceId);
                }

                // Récupération du type de participans
                var isCompetitor = reader.GetBoolean(reader.GetOrdinal("PctEstCompetiteur"));
                var isOrganiser  = reader.GetBoolean(reader.GetOrdinal("PctEstOrganisateur"));
                if (isCompetitor)
                {
                    Competitor c = new Competitor
                    {
                        Id            = reader.GetInt32(reader.GetOrdinal("PId")),
                        Nom           = reader.GetString(reader.GetOrdinal("PNom")),
                        Prenom        = reader.GetString(reader.GetOrdinal("PPrenom")),
                        Email         = reader.GetString(reader.GetOrdinal("PEmail")),
                        Phone         = reader.GetString(reader.GetOrdinal("PTelephone")),
                        DateNaissance = reader.GetDateTime(reader.GetOrdinal("PDateNaissance")),
                        Race          = r
                    };
                    r.Competitors.Add(c);
                }

                if (isOrganiser)
                {
                    Organizer o = new Organizer
                    {
                        Id            = reader.GetInt32(reader.GetOrdinal("PId")),
                        Nom           = reader.GetString(reader.GetOrdinal("PNom")),
                        Prenom        = reader.GetString(reader.GetOrdinal("PPrenom")),
                        Email         = reader.GetString(reader.GetOrdinal("PEmail")),
                        Phone         = reader.GetString(reader.GetOrdinal("PTelephone")),
                        DateNaissance = reader.GetDateTime(reader.GetOrdinal("PDateNaissance"))
                    };
                    r.Organisers.Add(o);
                }
            }

            return(list);
        }
Esempio n. 2
0
        public List <Race> GetRace()
        {
            List <Race> list = new List <Race>();

            // Récupération de l'élément racine <races>
            XmlElement elementRoot = documentXml.DocumentElement;

            // Récupération de chaque élément <race>
            foreach (XmlElement elementRace in elementRoot.ChildNodes)
            {
                Race race = new Race()
                {
                    Id          = int.Parse(elementRace[NODE_ID].InnerText),
                    Title       = elementRace[NODE_TITLE].InnerText,
                    Description = elementRace[NODE_DESCRIPTION].InnerText,
                    DateStart   = DateTime.Parse(elementRace[NODE_DATESTART].InnerText ?? string.Empty),
                    Town        = elementRace[NODE_TOWN].InnerText,
                    //Competitors = new List<Competitor>(),
                    //Organisers = new List<Organizer>()
                };

                // Récupération de chaque élément <competitor> si la balise <competitors> existe
                var elementRootCompet = elementRace[NODE_COMPETITOR + "s"] != null ? elementRace[NODE_COMPETITOR + "s"].ChildNodes : null;
                if (elementRootCompet != null)
                {
                    foreach (XmlElement elementCompet in elementRootCompet)
                    {
                        Competitor comp = new Competitor()
                        {
                            Id            = int.Parse(elementCompet[NODE_ID].InnerText),
                            Nom           = elementCompet[NODE_NOM].InnerText,
                            Prenom        = elementCompet[NODE_PRENOM].InnerText,
                            Email         = elementCompet[NODE_EMAIL].InnerText,
                            Phone         = elementCompet[NODE_PHONE].InnerText,
                            DateNaissance = DateTime.Parse(elementCompet[NODE_DATENAISSANCE].InnerText)
                        };
                        //race.Competitors.Add(comp);
                    }
                }

                // Récupération de chaque élément <organiser> si la balise <organisers> existe
                var elementRootOrgan = elementRace[NODE_ORGANISER + "s"] != null ? elementRace[NODE_ORGANISER + "s"].ChildNodes : null;
                if (elementRootOrgan != null)
                {
                    foreach (XmlElement elementOrgan in elementRootOrgan)
                    {
                        Organizer org = new Organizer()
                        {
                            Id            = int.Parse(elementOrgan[NODE_ID].InnerText),
                            Nom           = elementOrgan[NODE_NOM].InnerText,
                            Prenom        = elementOrgan[NODE_PRENOM].InnerText,
                            Email         = elementOrgan[NODE_EMAIL].InnerText,
                            Phone         = elementOrgan[NODE_PHONE].InnerText,
                            DateNaissance = DateTime.Parse(elementOrgan[NODE_DATENAISSANCE].InnerText)
                        };
                        //race.Organisers.Add(org);
                    }
                }

                list.Add(race);
            }

            return(list);
        }
Esempio n. 3
0
        private List <Race> BuildRaceList(DbDataReader reader)
        {
            List <Race> list = new List <Race>();

            while (reader.Read())
            {
                var raceId = reader.GetInt32(reader.GetOrdinal("CId"));

                Race r;
                if (list.All(x => x.Id != raceId))
                {
                    r = new Race
                    {
                        Id             = raceId,
                        Title          = reader.GetString(reader.GetOrdinal("CTitre")),
                        Description    = reader.GetString(reader.GetOrdinal("CDescription")),
                        DateStart      = reader.GetDateTime(reader.GetOrdinal("CDateStart")),
                        Town           = reader.GetString(reader.GetOrdinal("CVille")),
                        Distance       = reader.GetInt32(reader.GetOrdinal("CDistance")),
                        IdDifficulte   = reader.GetInt32(reader.GetOrdinal("CIdDifficulte")),
                        IdCategoryRace = reader.GetInt32(reader.GetOrdinal("CIdCategorieCourse")),
                        Difficulte     = new BO.Difficulte(),
                        CategoryRace   = new CategoryRace(),
                        Competitors    = new List <Competitor>()
                    };
                    list.Add(r);
                }
                else
                {
                    r = list.Single(x => x.Id == raceId);
                }

                // Récupération de la difficulte
                var difficulte = reader.GetInt32(reader.GetOrdinal("CIdDifficulte"));
                if (difficulte != 0)
                {
                    BO.Difficulte d = new BO.Difficulte
                    {
                        Id      = reader.GetInt32(reader.GetOrdinal("DId")),
                        Libelle = reader.GetString(reader.GetOrdinal("DLibelle")),
                    };
                    r.Difficulte = d;
                }

                // Récupération de la catégorie
                var categorie = reader.GetInt32(reader.GetOrdinal("CIdCategorieCourse"));
                if (categorie != 0)
                {
                    CategoryRace ca = new CategoryRace
                    {
                        Id    = reader.GetInt32(reader.GetOrdinal("CAId")),
                        Title = reader.GetString(reader.GetOrdinal("CALibelle")),
                    };
                    r.CategoryRace = ca;
                }

                // Récupération du type de participants
                var isCompetitor = reader.GetBoolean(reader.GetOrdinal("PctEstCompetiteur"));
                var isOrganiser  = reader.GetBoolean(reader.GetOrdinal("PctEstOrganisateur"));
                if (isCompetitor)
                {
                    Competitor c = new Competitor
                    {
                        Id            = reader.GetInt32(reader.GetOrdinal("PId")),
                        Nom           = reader.GetString(reader.GetOrdinal("PNom")),
                        Prenom        = reader.GetString(reader.GetOrdinal("PPrenom")),
                        Email         = reader.GetString(reader.GetOrdinal("PEmail")),
                        Phone         = reader.GetString(reader.GetOrdinal("PTelephone")),
                        DateNaissance = reader.GetDateTime(reader.GetOrdinal("PDateNaissance")),
                        Race          = r
                    };
                    r.Competitors.Add(c);
                }

                if (isOrganiser)
                {
                    Organizer o = new Organizer
                    {
                        Id            = reader.GetInt32(reader.GetOrdinal("PId")),
                        Nom           = reader.GetString(reader.GetOrdinal("PNom")),
                        Prenom        = reader.GetString(reader.GetOrdinal("PPrenom")),
                        Email         = reader.GetString(reader.GetOrdinal("PEmail")),
                        Phone         = reader.GetString(reader.GetOrdinal("PTelephone")),
                        DateNaissance = reader.GetDateTime(reader.GetOrdinal("PDateNaissance"))
                    };
                }
            }

            return(list);
        }