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); }
public static async Task SeedData(DataContext context, UserManager <AppUser> userManager) { if (!userManager.Users.Any()) { AppUser user = new AppUser() { UserName = "******", Email = "*****@*****.**", DisplayName = "Default user" }; await userManager.CreateAsync(user, "P4$$w0rd"); } List <Language> Languages = new List <Language> { new Language { IsoCode2 = "fr" }, new Language { IsoCode2 = "nl" }, new Language { IsoCode2 = "en" } }; if (!context.Languages.Any()) { context.Languages.AddRange(Languages); } if (!context.Customers.Any()) { context.Customers.Add(new Customer { Name = "Default customer" }); } if (!context.Suppliers.Any()) { context.Suppliers.Add(new Supplier { Name = "Default supplier" }); } if (!context.Products.Any()) { context.Products.AddRange(new Product[] { new Product { Price = 100M, ProductLanguages = new List <ProductLanguage>() { new ProductLanguage { Name = "Default product 1", Description = "This is a generic product.", Language = Languages.Single(x => x.IsoCode2 == "fr") } } }, new Product { Price = 499.99M, ProductLanguages = new List <ProductLanguage>() { new ProductLanguage { Name = "Default product 2", Description = "This is a generic product.", Language = Languages.Single(x => x.IsoCode2 == "nl") } } }, new Product { Price = 1000M, ProductLanguages = new List <ProductLanguage>() { new ProductLanguage { Name = "Default product 3", Description = "This is a generic product.", Language = Languages.Single(x => x.IsoCode2 == "en") } } } }); } if (context.ChangeTracker.HasChanges()) { context.SaveChanges(); } }