Пример #1
0
        public async Task <NowPlaying> StartStopAsync(bool isPlaying)
        {
            _context.Player.IsPlaying = isPlaying;
            await _context.SaveChangesAsync().ConfigureAwait(false);

            return(_context.Player);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
            }
        }