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); }
public HistoryRepository([NotNull] PartyTubeDbContext context, [NotNull] AppSettings appSettings, [NotNull] IVideoRepository videoRepository) { _context = context; _appSettings = appSettings; _videoRepository = videoRepository; }
public Task RemoveAsync(int id, [NotNull] PartyTubeDbContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } return(RemovePrivateAsync(id, context, false)); }
public PartyTubeDbContextMock() { var options = new DbContextOptionsBuilder <PartyTubeDbContext>() .UseInMemoryDatabase($"InMemoryDB{Guid.NewGuid()}") .Options; Context = new PartyTubeDbContext(options); Context.Database.EnsureDeleted(); }
public NowPlayingRepository([NotNull] PartyTubeDbContext context, [NotNull] IVideoRepository videoRepository, [NotNull] ICurrentPlaylistRepository currentPlaylistRepository, [NotNull] IHistoryRepository historyRepository) { _context = context; _videoRepository = videoRepository; _currentPlaylistRepository = currentPlaylistRepository; _historyRepository = historyRepository; }
public Task <HistoryItem> AddAsync([NotNull] VideoItem videoItem, [NotNull] PartyTubeDbContext context) { if (videoItem == null) { throw new ArgumentNullException(nameof(videoItem)); } if (context == null) { throw new ArgumentNullException(nameof(context)); } return(AddPrivateAsync(videoItem, context, false)); }
private async Task <HistoryItem> AddPrivateAsync([NotNull] VideoItem videoItem, [NotNull] PartyTubeDbContext context, bool isSave) { videoItem = await _videoRepository.GetAttachedOfFoundedAsync(videoItem, context).ConfigureAwait(false); var historyItem = new HistoryItem(videoItem); await context.History.AddAsync(historyItem).ConfigureAwait(false); if (isSave) { await context.SaveChangesAsync().ConfigureAwait(false); } return(historyItem); }
private async Task RemovePrivateAsync(int id, [NotNull] PartyTubeDbContext context, bool isSave) { var toRemove = await context.CurrentPlaylist.FirstOrDefaultAsync(s => s.Id == id).ConfigureAwait(false); if (toRemove == null) { return; } var reorder = await context.CurrentPlaylist.Where(w => w.Order > toRemove.Order) .ToArrayAsync() .ConfigureAwait(false); foreach (var item in reorder) { item.Order--; } context.CurrentPlaylist.Remove(toRemove); if (isSave) { await context.SaveChangesAsync().ConfigureAwait(false); } }
public PartyTubeDbContextSeedData(PartyTubeDbContext context, IHostingEnvironment env) { _context = context; _env = env; }
public CurrentPlaylistRepository([NotNull] PartyTubeDbContext context, [NotNull] IVideoRepository videoRepository) { _context = context; _videoRepository = videoRepository; }
public VideoRepository([NotNull] PartyTubeDbContext context) { _context = context; }