/// <summary> /// Method to add new type in car types. /// </summary> public void AddNewType() { CarRentalManagementEntities entities = new CarRentalManagementEntities(); CarType carType = new CarType() { Type = textBoxCarType.Text }; try { entities.CarTypes.Add(carType); entities.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot add Car Type to database" + ex.InnerException.InnerException.Message); return; } this.DialogResult = DialogResult.OK; entities.Dispose(); Close(); }
private void ButtonAddCarMake_Click(object sender, EventArgs e) { CarRentalManagementEntities entities = new CarRentalManagementEntities(); CarMake carMake = new CarMake() { Make = textBoxAddCarMake.Text }; try { entities.CarMakes.Add(carMake); entities.SaveChanges(); } catch (Exception ex) { MessageBox.Show("Cannot add Car Make to database" + ex.InnerException.InnerException.Message); return; } this.DialogResult = DialogResult.OK; entities.Dispose(); Close(); }