public async Task <int> AddAsync(TEntity entity) { DbSet <TEntity> dbSet = context.Set <TEntity>(); dbSet.Add(entity); context.Entry(entity).State = EntityState.Added; return(await context.SaveChangesAsync()); }
public static async Task <int> UpdateAsync(TEntity entity) { using (var context = new TalentAcquisitionEntities()) { DbSet <TEntity> dbSet = context.Set <TEntity>(); dbSet.Attach(entity); context.Entry(entity).State = EntityState.Modified; return(await context.SaveChangesAsync()); } }
public static async Task <int> DeleteAsync(Expression <Func <TEntity, bool> > filter) { using (var context = new TalentAcquisitionEntities()) { var res = await FindAsync(filter : filter); DbSet <TEntity> dbSet = context.Set <TEntity>(); dbSet.Attach(res); dbSet.Remove(res); return(await context.SaveChangesAsync()); } }