Exemplo n.º 1
0
        public async Task MakeSelection(long filmId, string userId)
        {
            await _dbContext.WatchNextSelectionRecords.AddAsync(new WatchNextSelectionRecord
            {
                FilmId           = filmId,
                UserId           = userId,
                SelectedDateTime = _clock.UtcNow
            });

            await _dbContext.SaveChangesAsync();

            _memoryCache.Remove(CacheKeys.WatchNext(userId));
        }
Exemplo n.º 2
0
        public async Task ExpireSelection(long filmId, bool watched = true)
        {
            var selectionRecord = await _dbContext.WatchNextSelectionRecords
                                  .Where(x => x.FilmId == filmId && !x.ExpiredDateTime.HasValue)
                                  .SingleOrDefaultAsync();

            selectionRecord.ExpiredDateTime = _clock.UtcNow;
            selectionRecord.Watched         = watched ? true : false;

            await _dbContext.SaveChangesAsync();

            _memoryCache.Remove(CacheKeys.WatchNext(selectionRecord.UserId));
        }
Exemplo n.º 3
0
        public async Task <FilmRecord> GetActiveWatchNext(string userId)
        {
            return(await _memoryCache.GetOrCreateAsync(CacheKeys.WatchNext(userId), async entry =>
            {
                var selectionRecord = await _dbContext.WatchNextSelectionRecords
                                      .Where(x => x.UserId == userId && !x.ExpiredDateTime.HasValue)
                                      .SingleOrDefaultAsync();

                if (selectionRecord == null)
                {
                    return null;
                }

                return await _dbContext.FilmRecords
                .Where(item => item.Id == selectionRecord.FilmId)
                .SingleOrDefaultAsync();
            }));
        }