public static bool DeleteItem(int id) { using (PitmanContext context = new PitmanContext()) { Person entity = context.Persons.FirstOrDefault(o => o.Id == id); if (entity != null) { context.Entry(entity).State = EntityState.Deleted; return context.SaveChanges() > 0; } } return false; }
public static bool AddOrUpdate(Person model) { using (PitmanContext context = new PitmanContext()) { if (model.Id > 0) { context.Persons.Attach(model); context.Entry(model).State = EntityState.Modified; return context.SaveChanges() > 0; } else { context.Persons.Add(model); return context.SaveChanges() > 0; } } }