Exemplo n.º 1
0
        public static Dictionary <string, object> getMovies(int id)
        {
            MovieEntities movieEntities        = new MovieEntities();
            Dictionary <string, object> result = new Dictionary <string, object>();
            Movie movie = movieEntities.Movie.Where(m => m.id == id).FirstOrDefault();

            if (movie == null)
            {
                result.Add("error", ConstantValue.MovieNotFound);
                return(result);
            }
            else
            {
                MovieService.convertObjectToDictionary(result, movie);
                return(result);
            }
        }
Exemplo n.º 2
0
        public static Dictionary <string, object> rate(int movieId, int score)
        {
            MovieEntities movieEntities = new MovieEntities();
            int           userId        = SessionService.getSession();
            Movie         movie         = movieEntities.Movie.Where(m => m.id == movieId).FirstOrDefault();
            Rate          rate          = movieEntities.Rate.Where(r => r.movie_id == movieId && r.user_id == userId).FirstOrDefault();

            if (rate == null)
            {
                MovieService.updateMovieRate(movie, score);
                movie.likes += 1;
                Rate newRate = new Rate
                {
                    movie_id = movieId,
                    user_id  = userId,
                    score    = score
                };
                movieEntities.Rate.Add(newRate);
            }
            else
            {
                MovieService.updateMovieRate(movie, rate, score);
                if (score != rate.score)
                {
                    rate.score = score;
                }
            }
            movieEntities.SaveChanges();
            Dictionary <string, object> results = new Dictionary <string, object>
            {
                { ConstantValue.Rate, movie.rate },
                { ConstantValue.Likes, movie.likes }
            };

            return(results);
        }