示例#1
0
        private void cmdDelete_Click(object sender, EventArgs e)
        {
            var selectedID = int.Parse(DgvAdresses.SelectedRows[0].Cells[3].Value.ToString());

            using (var context = new ContactBoockContext())
            {
                ContactAdress AddressToDelete = (ContactAdress)(from data in context.ContactAdresses
                                                                where data.ContactAdressID == selectedID
                                                                select data).First();
                context.ContactAdresses.Remove(AddressToDelete);
                context.SaveChanges();
                contactsDataGridView_SelectionChanged(null, null);
                isEnableAdress(false);
            }
        }
示例#2
0
        private void cmdSaveAdress_Click(object sender, EventArgs e)
        {
            using (var context = new ContactBoockContext())
            {
                var selectedID = int.Parse(contactsDataGridView.SelectedRows[0].Cells[0].Value.ToString());
                if (selectedID > 0)
                {
                    var selectedAdress = context.ContactAdresses.Where(data => data.ContactID == selectedID).Select(data => data.Adress).ToList();

                    ContactAdress ContactToAdd = new ContactAdress();
                    ContactToAdd.ContactID    = selectedID;
                    ContactToAdd.Adress       = txtAdress.Text;
                    ContactToAdd.AdressTypeID = (int)cbTypeOfAdress.SelectedValue;
                    context.ContactAdresses.Add(ContactToAdd);
                    context.SaveChanges();
                    contactsDataGridView_SelectionChanged(null, null);
                    isEnableAdress(false);
                }
            }
        }