private void Button_Click_1(object sender, RoutedEventArgs e) { using (Al_MujahidEntities context = new Al_MujahidEntities()) { CUSTOMER customer = new CUSTOMER(); if (this.pHONETextBox.Text.Equals("")) { customer.PHONE = 0000; } else { var phone = Convert.ToInt64(this.pHONETextBox.Text.ToString()); customer.PHONE = phone; } customer.COMPANY = this.cOMPANYTextBox.Text; context.CUSTOMERS.Add(customer); context.SaveChanges(); Close(); } }
private void MenuItem_Click_3(object sender, RoutedEventArgs e) { CUSTOMER c = (CUSTOMER)cUSTOMERSDataGrid.SelectedItem; using (Al_MujahidEntities context = new Al_MujahidEntities()) { MessageBox.Show(c.CUS_ID.ToString()); var myObject = new CUSTOMER { CUS_ID = c.CUS_ID }; context.CUSTOMERS.Attach(myObject); context.CUSTOMERS.Remove(myObject); context.SaveChanges(); CUSTOMERS_Load(); } }