private void btnLoad_Click(object sender, EventArgs e) { using (var MyModelEntities = new MyCustomerModel()) { dataGridView1.DataSource = MyModelEntities.Customers.ToList(); } }
private void btnSaveModels_Click(object sender, EventArgs e) { customer.Name = textClientName.Text; customer.BirthDate = Convert.ToDateTime(dateTimePicker1.Text); customer.Location = textLocation.Text; using (var customerModel = new MyCustomerModel()) { customerModel.Customers.Add(customer); customerModel.SaveChanges(); MessageBox.Show("Customer added."); } }
private void btnUpdateModels_Click(object sender, EventArgs e) { int customerID = Convert.ToInt32(textClientId.Text); if (customerModel.Customers.Where(r => r.CostumerID == customerID).FirstOrDefault() != null) { customer.CostumerID = customerModel.Customers.Where(c => c.CostumerID == customerID).FirstOrDefault().CostumerID; customer.BirthDate = Convert.ToDateTime(dateTimePicker1.Text); customer.Location = textLocation.Text; customer.Name = textClientName.Text; using (var customerModel = new MyCustomerModel()) { customerModel.Entry(customer).State = System.Data.Entity.EntityState.Modified; customerModel.SaveChanges(); MessageBox.Show("Customer updated."); } } else { MessageBox.Show("Please insert valid customer ID"); } }