public async Task <VideoItem> GetAttachedOfFoundedAsync([NotNull] VideoItem videoItem, [NotNull] PartyTubeDbContext context) { if (videoItem == null) { throw new ArgumentNullException(nameof(videoItem)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } if (videoItem.Id == 0) { var identifier = videoItem.VideoIdentifier; var search = await context.Video.FirstOrDefaultAsync(s => s.VideoIdentifier == identifier) .ConfigureAwait(false); if (search != null) { videoItem = search; } } else if (context.Entry(videoItem).State == EntityState.Detached) { context.Video.Attach(videoItem); } return(videoItem); }