public IEnumerable <Order2021> ParseCsvFile(string file) { TextFieldParser parser = new TextFieldParser(file); parser.TextFieldType = FieldType.Delimited; parser.SetDelimiters(","); while (!parser.EndOfData) { string[] fields = parser.ReadFields(); if (fields[0] == "ID") // header { continue; } var order = new Order2021() { WordpressId = int.Parse(fields[0]), // Oh designers, please use "normal" characters as much as possible!! EventName = fields[1].Replace("’", "'").Replace("×", "x"), FirstName = fields[9], Email = fields[10], Title = fields[14], LastName = fields[15], Phone = fields[16], LocalisedNationality = fields[17], OnlineNickname = fields[18], DiscordNickname = fields[19], DoBString = fields[20] }; yield return(order); } parser.Close(); }
private void UpdateEntrant(DataEntities context, Contestant contestant, Order2021 order) { if (IsSanitisedDateOfBirth(order.DateOfBirth)) { contestant.DateofBirth = order.DateOfBirth; } if (order.OnlineNickname != null) { // Contestants may use different nicknames for different servers, and submit separate orders if (contestant.OnlineNicknames == null) { contestant.OnlineNicknames = order.OnlineNickname; } else if (!contestant.OnlineNicknames.Contains(order.OnlineNickname)) { contestant.OnlineNicknames += "; " + order.OnlineNickname; } } if (order.DiscordNickname != null) { contestant.DiscordNickname = order.DiscordNickname; } if (!string.IsNullOrEmpty(order.Email)) { contestant.email = order.Email; } context.SaveChanges(); }
private Contestant CreateEntrant(DataEntities context, Order2021 order) { var contestant = new Contestant() { Firstname = order.FirstName ?? "", Lastname = order.LastName ?? "", Nationality = order.LocalisedNationality, Title = order.Title, Male = (order.Title == "Mr"), DateofBirth = SanitiseDateOfBirth(order.DateOfBirth), OnlineNicknames = order.OnlineNickname, DiscordNickname = order.DiscordNickname, email = order.Email }; context.Contestants.Add(contestant); context.SaveChanges(); return(contestant); }