public async Task <NowPlaying> StartStopAsync(bool isPlaying) { _context.Player.IsPlaying = isPlaying; await _context.SaveChangesAsync().ConfigureAwait(false); return(_context.Player); }
public async Task ReorderAsync([NotNull] int[] ids) { if (ids == null) { throw new ArgumentNullException(nameof(ids)); } var items = await _context.CurrentPlaylist.ToDictionaryAsync(item => item.Id, item => item) .ConfigureAwait(false); var i = 1; foreach (var id in ids) { if (!items.ContainsKey(id)) { continue; } items[id].Order = i; i++; } var notInRange = items.Where(w => !ids.Contains(w.Key)) .Select(s => s.Value) .OrderBy(o => o.Order) .ToArray(); foreach (var item in notInRange) { item.Order = i; i++; } await _context.SaveChangesAsync().ConfigureAwait(false); }
public async Task DeleteByIdAsync(int id) { var del = await _context.History.FirstOrDefaultAsync(s => s.Id == id).ConfigureAwait(false); if (del == null) { return; } _context.History.Remove(del); await _context.SaveChangesAsync().ConfigureAwait(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); } }