public Story Save(Story entity) { if (entity.Id == 0) { //new entry _db.Stories.Add(entity); } else { //existing entry _db.Stories.Attach(entity); _db.Entry(entity).State = EntityState.Modified; } _db.SaveChanges(); return(entity); }
public Character Save(Character entity) { if (entity.Story == null) { throw new ArgumentException("A Character requires a Story."); } if (entity.Id == 0) { //new entry _db.Characters.Add(entity); } else { //existing entry _db.Characters.Attach(entity); _db.Entry(entity).State = EntityState.Modified; } _db.SaveChanges(); return(entity); }