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)); }
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)); }
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(); })); }