Ejemplo n.º 1
0
        private Contestant CreateEntrant(DataEntities context,
                                         Order2018 order,
                                         Order2018.Attendee entrant,
                                         Dictionary <string, string> countries)
        {
            if (!countries.ContainsKey(entrant.CountryCode))
            {
                throw new ArgumentOutOfRangeException($"Unknown country code {entrant.CountryCode}");
            }

            var contestant = new Contestant()
            {
                Firstname       = entrant.FirstName ?? "",
                Lastname        = entrant.LastName ?? "",
                Nationality     = countries[entrant.CountryCode],
                Title           = entrant.Title,
                Male            = (entrant.Title == "Mr"),
                DateofBirth     = SanitiseDateOfBirth(order.DateOfBirth),
                OnlineNicknames = order.OnlineNicknames,
                DiscordNickname = order.DiscordNickname,
                Whatsapp        = order.Whatsapp,
                email           = entrant.Email
            };

            context.Contestants.Add(contestant);

            context.SaveChanges();
            return(contestant);
        }
Ejemplo n.º 2
0
        public IEnumerable <Order2018> ParseJsonFile(string file)
        {
            var orders = new List <Order2018>();

            dynamic json = JsonConvert.DeserializeObject(File.ReadAllText(file));

            foreach (var o in json)
            {
                var order2018 = new Order2018();
                var order     = o.Value;
                order2018.BookingId       = order.booking_id.Value;
                order2018.BookingPrice    = decimal.Parse(order.booking_price.Value);
                order2018.BookingSpaces   = order.booking_spaces.Value;
                order2018.BookingStatus   = order.booking_status.Value;
                order2018.DiscordNickname = order["Discord username"].Value;
                order2018.OnlineNicknames = order["Usernames for relevant platforms"].Value;
                order2018.Whatsapp        = (order["WhatsApp with this number"] != null && order["WhatsApp with this number"].Value == "1");
                order2018.Timestamp       = order.timestamp.Value;
                order2018.DoBString       = order.date_of_birth.Value;
                var attendee = new Order2018.Attendee()
                {
                    Title       = order.attendees.customer.title.Value,
                    FirstName   = order.attendees.customer.first_name.Value,
                    LastName    = order.attendees.customer.last_name.Value,
                    CountryCode = SubstituteCountryCode(order.attendees.customer.country_to_represent.Value),
                    Email       = order.attendees.customer.email.Value,
                };
                attendee.FirstName = attendee.FirstName.DecodeEncodedNonAsciiCharacters();
                attendee.LastName  = attendee.LastName.DecodeEncodedNonAsciiCharacters();
                order2018.Attendees.Add(attendee);
                foreach (var o1 in order.events)
                {
                    var evt = o1.Value;
                    order2018.Events.Add(new Order2018.Event()
                    {
                        Code = Substitute(evt.event_id.Value)
                    });
                }
                orders.Add(order2018);
            }

            return(orders);
        }