public void Delete(int id) { using (var context = new DataContext()) { context.Authors.Remove(context.Authors.First(x => x.Id == id)); context.SaveChanges(); } }
public Author Save(Author author) { using (var context = new DataContext()) { if (author.Id == 0) { context.Authors.Add(author); } else { context.Entry(author).State = EntityState.Modified; context.Authors.AddOrUpdate(author); } context.SaveChanges(); } return author; }