/// <summary> /// Called when the delete button is pressed /// it deletes room, reservation guest, room type, room status, etc. /// </summary> private void DeleteEntity <T>(T entity, int id) where T : class { if (id != 0) { try { using (GrandLuxEntities context = new GrandLuxEntities()) { context.Entry(entity).State = EntityState.Deleted; context.SaveChanges(); } MetroMessageBox.Show(this, $"A record has been removed", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowData(entity); } catch (Exception) { MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MetroMessageBox.Show(this, "Please click on a row to delete it", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }