private static void ImportContactToDatabase(ContactDTO contactDTO)
 {
     if (contactDTO.Name == null)
     {
         throw new ArgumentException("Name is required");
     }
     var newContact = new Contact()
     {
         Name = contactDTO.Name,
         Company = contactDTO.Company,
         Position = contactDTO.Position,
         Url = contactDTO.Site,
         Notes = contactDTO.Notes
     };
     if (contactDTO.Emails != null)
     {
         newContact.Emails = contactDTO.Emails.Select(e => new Email() { EmailAddress = e }).ToList();
     }
     if (contactDTO.Phones != null)
     {
         newContact.Phones = contactDTO.Phones.Select(p => new Phone() { PhoneNumber = p }).ToList();
     }
     var context = new PhonebookContext();
     context.Contacts.Add(newContact);
     context.SaveChanges();
 }
        public static void Main()
        {
            var context = new PhonebookContext();
            var contacts = context.Contacts
                .Include(c => c.Emails)
                .Include(c => c.Phones);

            foreach (var contact in contacts)
            {
                Console.WriteLine("Name: {0}{7}Company: {1}{7}Position: {2}{7}Note: {3}{7}Url: {4}{7}Emails: {5}{7}Phones: {6}{7}",
                    contact.Name,
                    contact.Company,
                    contact.Position,
                    contact.Note ?? string.Empty,
                    contact.Url ?? string.Empty,
                    string.Join(", ", contact.Emails.Select(e => e.EmailAddress)),
                    string.Join(", ", contact.Phones.Select(p => p.PhoneNumber)),
                    Environment.NewLine);
            }
        }
        public static void Main()
        {
            var context = new PhonebookContext();

            var json = File.ReadAllText(@"..\..\contacts.json");
            var jsonSerializer = new JavaScriptSerializer();
            var parsedContacts = jsonSerializer.Deserialize<ContactDTO[]>(json);

            foreach (var contactDTO in parsedContacts)
            {
                try
                {
                    ImportContactToDatabase(contactDTO);
                    Console.WriteLine("Contact {0} imported", contactDTO.Name);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: {0}", ex.Message);
                }
            }
        }
 static void Main()
 {
     var context = new PhonebookContext();
     var contacts = context.Contacts
         .Include(c => c.Phones)
         .Include(c => c.Emails)
         .ToList();
     foreach (var contact in contacts)
     {
         Console.WriteLine("Name: {0}", contact.Name);
         Console.WriteLine("  Position: {0}", contact.Position);
         Console.WriteLine("  Company: {0}", contact.Company);
         Console.WriteLine("  Emails: {0}",
             string.Join(", ", contact.Emails.Select(e => e.EmailAddress)));
         Console.WriteLine("  Phones: {0}",
             string.Join(", ", contact.Phones.Select(e => e.PhoneNumber)));
         Console.WriteLine("  Url: {0}", contact.Url);
         Console.WriteLine("  Notes: {0}", contact.Notes);
         Console.WriteLine();
     }
 }
        static void Main()
        {
            var context  = new PhonebookContext();
            var contacts = context.Contacts
                           .Include(c => c.Phones)
                           .Include(c => c.Emails)
                           .ToList();

            foreach (var contact in contacts)
            {
                Console.WriteLine("Name: {0}", contact.Name);
                Console.WriteLine("  Position: {0}", contact.Position);
                Console.WriteLine("  Company: {0}", contact.Company);
                Console.WriteLine("  Emails: {0}",
                                  string.Join(", ", contact.Emails.Select(e => e.EmailAddress)));
                Console.WriteLine("  Phones: {0}",
                                  string.Join(", ", contact.Phones.Select(e => e.PhoneNumber)));
                Console.WriteLine("  Url: {0}", contact.Url);
                Console.WriteLine("  Notes: {0}", contact.Notes);
                Console.WriteLine();
            }
        }