示例#1
0
        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);
        }
示例#2
0
 public HistoryRepository([NotNull] PartyTubeDbContext context,
                          [NotNull] AppSettings appSettings,
                          [NotNull] IVideoRepository videoRepository)
 {
     _context         = context;
     _appSettings     = appSettings;
     _videoRepository = videoRepository;
 }
示例#3
0
        public Task RemoveAsync(int id, [NotNull] PartyTubeDbContext context)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(RemovePrivateAsync(id, context, false));
        }
示例#4
0
        public PartyTubeDbContextMock()
        {
            var options = new DbContextOptionsBuilder <PartyTubeDbContext>()
                          .UseInMemoryDatabase($"InMemoryDB{Guid.NewGuid()}")
                          .Options;

            Context = new PartyTubeDbContext(options);
            Context.Database.EnsureDeleted();
        }
示例#5
0
 public NowPlayingRepository([NotNull] PartyTubeDbContext context,
                             [NotNull] IVideoRepository videoRepository,
                             [NotNull] ICurrentPlaylistRepository currentPlaylistRepository,
                             [NotNull] IHistoryRepository historyRepository)
 {
     _context                   = context;
     _videoRepository           = videoRepository;
     _currentPlaylistRepository = currentPlaylistRepository;
     _historyRepository         = historyRepository;
 }
示例#6
0
        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));
        }
示例#7
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);
        }
示例#8
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);
            }
        }
 public PartyTubeDbContextSeedData(PartyTubeDbContext context, IHostingEnvironment env)
 {
     _context = context;
     _env     = env;
 }
示例#10
0
 public CurrentPlaylistRepository([NotNull] PartyTubeDbContext context,
                                  [NotNull] IVideoRepository videoRepository)
 {
     _context         = context;
     _videoRepository = videoRepository;
 }
示例#11
0
 public VideoRepository([NotNull] PartyTubeDbContext context)
 {
     _context = context;
 }