/// <summary> /// Called when the add button is pressed /// it addes or updates room, reservation guest, room type, room status, etc. /// </summary> private void AddEntity <T>(T entity, bool inputsValidation, int id) where T : class { if (inputsValidation) { try { string state = (id == 0) ? "Added" : "Modified"; //To print a message to the user of wether an item is added or modified using (GrandLuxEntities context = new GrandLuxEntities()) { context.Set <T>().AddOrUpdate(entity); context.SaveChanges(); } MetroMessageBox.Show(this, $"A record has been {state}", "Done", MessageBoxButtons.OK, MessageBoxIcon.Information); ShowData(entity); //To fill the Data grid view and clear the input values } catch (Exception) { MetroMessageBox.Show(this, "Something went Wrong, try again", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MetroMessageBox.Show(this, "Please fill the missing data or click on a row to update it", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }