Пример #1
0
        public void CreateNewContact(Contact contact, AddressModel address, string contactType)
        {
            using (var dataContext = new DataContext.AdressbookDataContext())
            {
                var newContact = new DataContext.Contact();
                newContact.Name      = contact.Name;
                newContact.Email     = contact.Email;
                newContact.Telephone = contact.Telephone;

                var newAddress = new DataContext.Address();
                newAddress.StreetAddress = address.StreetAddress;
                newAddress.City          = address.City;
                newAddress.PostalCode    = address.PostalCode;

                var contactId      = newContact.Id;
                var newContactType = new DataContext.ContactType();
                newContactType.ContactType1 = contactType;
                newContactType.ContactId    = contactId;

                var newAddressContactLink = new DataContext.AddressContactLink();
                newAddressContactLink.ContactId = newContact.Id;
                newAddressContactLink.AddressId = newAddress.Id;

                dataContext.Contact.Add(newContact);
                dataContext.Address.Add(newAddress);
                dataContext.ContactType.Add(newContactType);
                dataContext.AddressContactLink.Add(newAddressContactLink);
                dataContext.SaveChanges();
            }
        }
Пример #2
0
        private void CreateNewContactButton_Click(object sender, EventArgs e)
        {
            DataAccess dataAccess  = new DataAccess();
            var        sendContact = new View_Models.Contact();

            sendContact.Name      = NameTextBox.Text;
            sendContact.Email     = EmailTextBox.Text;
            sendContact.Telephone = TelephoneTextBox.Text;

            var sendAddress = new View_Models.AddressModel();

            sendAddress.StreetAddress = StreetAddressTextBox.Text;
            sendAddress.PostalCode    = PostalCodeTextBox.Text;
            sendAddress.City          = CityTextBox.Text;
            var sendTypeContact = ContactTypeComboBox.SelectedItem.ToString();



            dataAccess.CreateNewContact(sendContact, sendAddress, sendTypeContact);
            GetAllContacts();
        }