public virtual EntityState Insert(T entity) { try { dbSet.Add(entity); context.SaveChanges(); return(context.Entry(entity).State); } catch (Exception ex) { return(EntityState.Added); } finally { } }
private void btnsave_Click(object sender, EventArgs e) { model.CodePointVente = Convert.ToInt32(textcode.Text.Trim()); model.Libelle = textlibelle.Text.Trim(); model.Adresse = textadresse.Text.Trim(); model.Ville = textlibelle.Text.Trim(); if (Code > 0) { db.Entry(model).State = EntityState.Modified; } else { db.PointVentes.Add(model); } db.SaveChanges(); Clear(); VenteDataGrid(); MessageBox.Show("Enregistrement avec succées"); }