예제 #1
0
        public RootEntity()
        {
            this.Contacts = new AdvisableCollection<Contact>();
            this.countries = new AdvisableCollection<Country>();

            foreach (string country in Populate.GetCountries())
            {
                this.countries.Add(new Country(country));
            }

            Country russia = this.countries.Single(c => c.Name == "Russia");

            foreach (string contactName in Populate.GetContacts())
            {
                string[] names = contactName.Split(' ');
                Contact contact = new Contact(names[0], names[1]);
                Address address = new Address
                {
                    AddressLine1 = "23, Ilyinka Street",
                    Town = "Moscow",
                    Zip = "103132",
                    Country = russia
                };
                contact.Addresses.Add(address);
                contact.PrincipalAddress = address;
                this.Contacts.Add(contact);
            }

            RecordingServices.DefaultRecorder.Clear();
        }
예제 #2
0
        public static List<Contact> GetContacts()
        {
            List<Contact> contacts = new List<Contact>();
            using ( DbConnection connection = GetConnection() )
            using ( DbCommand command = connection.CreateCommand() )
            {
                command.CommandText = "SELECT * FROM Contacts ORDER BY FirstName, LastName ASC";
                DbDataReader reader = command.ExecuteReader();
                while ( reader.Read() )
                {
                    Contact contact = new Contact( false )
                                          {
                                              Id = ToInt32( reader["ContactId"] ).Value,
                                              FirstName = ToString( reader["FirstName"] ),
                                              LastName = ToString( reader["LastName"] ),
                                              Company = ToString( reader["Company"] ),
                                              Position = ToString( reader["Position"] ),
                                              AddressLine1 = ToString( reader["AddressLine1"] ),
                                              AddressLine2 = ToString( reader["AddressLine2"] ),
                                              Zip = ToString( reader["Zip"] ),
                                              Town = ToString( reader["Town"] ),
                                              CountryId = ToInt32( reader["CountryId"] )
                                          };
                    contacts.Add( contact );
                    contact.IsInitialized = true;
                }
            }

            return contacts;
        }