public static void Update(ModelCar modelCar) { if (modelCar.Id == 0) { repository.ModelCars.Add(modelCar); } repository.SaveChanges(); }
private void удалитьToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { ModelCar modelCar = dataGridView1.SelectedRows[0].DataBoundItem as ModelCar; Controller.Remove(modelCar); UpdateData(); } }
public NewModelForm(ModelCar modelCar = null) { InitializeComponent(); if (modelCar != null) { txtBxName.Text = modelCar.Name; this.modelCar = modelCar; } }
private void редактироватьToolStripMenuItem_Click(object sender, EventArgs e) { if (dataGridView1.SelectedRows.Count > 0) { ModelCar modelCar = dataGridView1.SelectedRows[0].DataBoundItem as ModelCar; NewModelForm form = new NewModelForm(modelCar); if (form.ShowDialog() == DialogResult.OK) { UpdateData(); } } }
private void btnOK_Click(object sender, EventArgs e) { if (txtBxName.Text == "") { MessageBox.Show("Укажите название модели"); return; } if (modelCar == null) { modelCar = new ModelCar(); } modelCar.Name = txtBxName.Text; Controller.Update(modelCar); DialogResult = DialogResult.OK; }
public static void Remove(ModelCar modelCar) { repository.ModelCars.Remove(modelCar); repository.SaveChanges(); }