public static void InitializePlatformResources(CompetitionContext context) { context.Database.EnsureCreated(); if (context.Competitions.Any()) { return; // DB has been seeded } var competition = new Competition[] { new Competition { CompetitionName = "NYP Global CTF", Status = "Active" } }; foreach (Competition c in competition) { context.Competitions.Add(c); } context.SaveChanges(); var competitionCategory = new CompetitionCategory[] { new CompetitionCategory { CategoryName = "Web" }, new CompetitionCategory { CategoryName = "Crypto" }, new CompetitionCategory { CategoryName = "Forensics" }, new CompetitionCategory { CategoryName = "Misc" } }; foreach (CompetitionCategory cc in competitionCategory) { context.CompetitionCategories.Add(cc); } context.SaveChanges(); }
internal static List <CompetitionCategory> ReadCategories(SqlDataReader reader) { var list = new List <CompetitionCategory>(); var stringList = ReadObject(reader, "Categories", "").Split(new[] { "++" }, StringSplitOptions.None); foreach (var pair in stringList) { var rulePair = pair.Split(new[] { "||" }, StringSplitOptions.None); int id; var compRule = new CompetitionCategory(); if (rulePair.Length < 2) { continue; } if (TryParse(rulePair[0], out id)) { compRule.Id = id; } compRule.Name = rulePair[1]; list.Add(compRule); } return(list); }