Beispiel #1
0
        public async Task AddNextMovie(int currentMovieId, int nextMovieId, int score)
        {
            NextMovie newEntry = new NextMovie
            {
                CurrentMovieId = currentMovieId,
                NextMovieId    = nextMovieId,
                Score          = score
            };
            await _context.AddAsync(newEntry);

            await _context.SaveChangesAsync();
        }
Beispiel #2
0
        public async Task UpdateNextMovieScore(int currentMovieId, int nextMovieId, int score)
        {
            // can be simplified with query by row Id, probably better if indexing is introduced
            NextMovie updateEntry = await _context.NextMovies.Where(m => m.CurrentMovieId == currentMovieId && m.NextMovieId == nextMovieId)
                                    .FirstOrDefaultAsync();

            if (updateEntry != null)
            {
                updateEntry.Score = score;
                await _context.SaveChangesAsync();
            }
        }
Beispiel #3
0
        /// <summary>
        /// Adds the movie to the NextMovies table with a const score and if it already exists, it just increments the score.
        /// </summary>
        /// <param name="userEmail"></param>
        /// <param name="movieId"></param>
        private void AddMovieToNextMovies(string userEmail, int movieId)
        {
            const int scoreIncrementation       = 1;
            History   previousMovieHistoryModel = _repository.GetLatestFromHistory(userEmail);

            if (previousMovieHistoryModel != null)
            {
                int previousMovieId = previousMovieHistoryModel.MovieId;
                List <NextMovie> nextMoviesFromDb = _repository.GetNextMoviesForMovieById(previousMovieId);

                NextMovie entry = nextMoviesFromDb.Where(m => m.NextMovieId == movieId).FirstOrDefault();

                if (entry == null)
                {
                    _repository.AddNextMovie(previousMovieId, movieId, scoreIncrementation);
                }
                else
                {
                    _repository.UpdateNextMovieScore(previousMovieId, movieId, entry.Score + scoreIncrementation);
                }
            }
        }