public virtual async Task <TEntity> UpdateAsync(int id, TEntity updateEntity) { // Check that the record exists. var entity = await ReadAsync(id); if (entity == null) { throw new Exception("Unable to find record with id '" + id + "'."); } // Update changes if any of the properties have been modified. _contactsApiDbContext.Entry(entity).CurrentValues.SetValues(updateEntity); _contactsApiDbContext.Entry(entity).State = EntityState.Modified; if (_contactsApiDbContext.Entry(entity).Properties.Any(property => property.IsModified)) { await _contactsApiDbContext.SaveChangesAsync(); } return(entity); }
public async Task UpdateAsync(T entity) { DbContext.Entry(entity).State = EntityState.Modified; await DbContext.SaveChangesAsync(); }