public void Change <TEntity>(TEntity entity, DbSet <TEntity> entities = null) where TEntity : class, new() { CheckNullEntity(entity); entities = entities ?? GetDbSet <TEntity>(); if (PageHelper.IsAdd <TEntity, int>(entity)) { entities.Add(entity); } else { Attach(entities, entity, EntityState.Modified); } }
public async Task <bool> SaveAsync <TEntity>(TEntity entity, DbSet <TEntity> entities = null) where TEntity : class, new() { CheckNullEntity(entity); entities = entities ?? GetDbSet <TEntity>(); if (PageHelper.IsAdd <TEntity, int>(entity)) { entities.Add(entity); } else { Attach(entities, entity, EntityState.Modified); } return(await SaveChangesAsync()); }