public void Add(Client entity) { using (var dbContext = new PoREntities(ConnectionString)) { dbContext.Clients.Add(entity); dbContext.SaveChanges(); } }
public void Add(BookedItem entity) { using (var dbContext = new PoREntities(ConnectionString)) { dbContext.BookedItems.Add(entity); dbContext.SaveChanges(); } }
public void Update(BookedItem entity) { using (var dbContext = new PoREntities(ConnectionString)) { // We could turn this into an upsert dbContext.BookedItems.Attach(entity); dbContext.Entry(entity).State = EntityState.Modified; dbContext.SaveChanges(); } }
public void Update(Item entity) { using (var dbContext = new PoREntities(ConnectionString)) { // We could turn this into an upsert dbContext.Items.Attach(entity); dbContext.Entry(entity).State = EntityState.Modified; // This Could cause problems. You could approach this like and upsert and do something like // AddOrUpdate(i=> i.id == entity.Id). Additionally you may want to set certain properties // of the entity to 'not modified' if they're null so as not to update the DB. dbContext.SaveChanges(); } }