Esempio n. 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();
        }
Esempio n. 2
0
        public static void Repopulate()
        {
            using (DbConnection connection = GetConnection())
            {
                DbCommand command;

                command             = connection.CreateCommand();
                command.CommandText = "DELETE FROM Contacts";
                command.ExecuteNonQuery();

                command             = connection.CreateCommand();
                command.CommandText = "DELETE FROM Countries";
                command.ExecuteNonQuery();

                command             = connection.CreateCommand();
                command.CommandText = "INSERT INTO Countries ( Name ) VALUES ( @Name )";
                DbParameter nameParam = command.AddParameter("Name", DbType.String, null);

                foreach (string country in Populate.GetCountries())
                {
                    nameParam.Value = country;
                    command.ExecuteNonQuery();
                }

                DbCommand command2 = connection.CreateCommand();
                command2.CommandText = "INSERT INTO Contacts ( FirstName, LastName ) VALUES ( @FirstName, @LastName )";
                DbParameter firstNameParam = command2.AddParameter("FirstName", DbType.String, null);
                DbParameter lastNameParam  = command2.AddParameter("LastName", DbType.String, null);

                foreach (string contact in Populate.GetContacts())
                {
                    string[] parts = contact.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    firstNameParam.Value = parts[0];
                    lastNameParam.Value  = parts[1];
                    command2.ExecuteNonQuery();
                }
            }
        }