public static async Task UpdateBlocksAsync <TEntity>(TEntity entity, BioContext dbContext) where TEntity : IContentEntity { var oldBlocks = await dbContext.Blocks .Where(b => b.ContentId == entity.Id).AsNoTracking() .ToListAsync(); foreach (var block in entity.Blocks) { block.ContentId = entity.Id; var oldBlock = oldBlocks.FirstOrDefault(b => b.Id == block.Id); if (oldBlock == null) { dbContext.Blocks.Add(block); } } foreach (var oldBlock in oldBlocks) { var block = entity.Blocks.FirstOrDefault(b => b.Id == oldBlock.Id); if (block == null) { dbContext.Remove(oldBlock); } else { dbContext.Attach(block); dbContext.Update(block); } } }
public async Task <TEntity> DeleteAsync(TEntity item, IBioRepositoryOperationContext?operationContext = null) { DbContext.Attach(item); DbContext.Remove(item); await SaveChangesAsync(); return(item); }