GetReviewsByMovieId() public method

Return the reviews by movieid
public GetReviewsByMovieId ( string movieId ) : Models.ReviewEntity>.IDictionary
movieId string
return Models.ReviewEntity>.IDictionary
コード例 #1
0
        // get : api/RateMovie?movieid=<mid>
        protected override string ProcessRequest()
        {
            // get query string parameters
            string queryParameters = this.Request.RequestUri.Query;
            if (queryParameters != null)
            {
                var qpParams = HttpUtility.ParseQueryString(queryParameters);

                string movieId = qpParams["movieid"];

                if (!string.IsNullOrEmpty(movieId))
                {
                    var tableMgr = new TableManager();
                    var movie = tableMgr.GetMovieById(movieId);
                    if (movie != null)
                    {
                        // Reset movie score
                        movie.MyScore = "0";
                        movie.Rating = "0";
                        tableMgr.UpdateMovieById(movie);

                        IDictionary<string, ReviewEntity> reviewEntities = tableMgr.GetReviewsByMovieId(movieId);
                        foreach (var pair in reviewEntities)
                        {
                            // Add code here
                            var response = Scorer.QueueScoreReview(movieId, pair.Value.ReviewId);
                            if (response.Contains("\"Error\""))
                            {
                                // There was an error - communicate this to user
                            }
                        }

                        return jsonSerializer.Value.Serialize(new { Status = "Error", UserMessage = "Queued rating reviews for this movie", ActualError = "" });
                    }
                    else
                    {
                        return jsonSerializer.Value.Serialize(new { Status = "Error", UserMessage = "Unable to find the movie", ActualError = "" });
                    }
                }
                else
                {
                    return jsonSerializer.Value.Serialize(new { Status = "Error", UserMessage = "Pass in movie ID", ActualError = "" });
                }
            }
            else
            {
                return jsonSerializer.Value.Serialize(new { Status = "Error", UserMessage = "Pass in movie ID", ActualError = "" });
            }
        }
コード例 #2
0
        internal static string GetMovieInfo(string name)
        {
            name = name.ToLower();
            string json = string.Empty;
            if (!CacheManager.TryGet<string>(CacheConstants.MovieInfoJson + name, out json))
            {

                try
                {
                    var tableMgr = new TableManager();

                    // get single movie object form database by its unique name
                    var movie = tableMgr.GetMovieByUniqueName(name);

                    if (movie != null)
                    {
                        MovieInfo movieInfo = new MovieInfo();
                        movieInfo.movieId = movie.MovieId;
                        movieInfo.Movie = movie;

                        // get reviews for movie by movie id
                        var reviewList = tableMgr.GetReviewsByMovieId(movie.MovieId);

                        // if reviews not null then add review to review list.
                        var userReviews = (reviewList != null) ?
                            reviewList.Select(review =>
                            {
                                ReviewerEntity reviewer = tableMgr.GetReviewerById(review.Value.ReviewerId);
                                ReviewEntity objReview = review.Value as ReviewEntity;

                                objReview.ReviewerName = reviewer.ReviewerName;
                                objReview.CriticsRating = objReview.SystemRating == 0 ? "" : (objReview.SystemRating == -1 ? 0 : 100).ToString();

                                //objReview.OutLink = reviewer.ReviewerImage;
                                return objReview;
                            }) :
                            Enumerable.Empty<ReviewEntity>();

                        //add reviewlist to movieinfo reviews
                        movieInfo.MovieReviews = userReviews.ToList();

                        // serialize movie object and return.
                        json = jsonSerializer.Value.Serialize(movieInfo);
                    }
                    else
                    {
                        // if movie not found then return empty string
                        json = string.Empty;
                    }

                    CacheManager.Add<string>(CacheConstants.MovieInfoJson + name, json);
                }
                catch (Exception ex)
                {
                    // if any error occured then return User friendly message with system error message
                    // use jsonError here because more custumizable
                    json = jsonSerializer.Value.Serialize(
                    new
                    {
                        Status = "Error",
                        UserMessage = "Unable to find " + name + " movie.",
                        ActualError = ex.Message
                    });
                }
            }
            return json;
        }
コード例 #3
0
ファイル: MovieInfoController.cs プロジェクト: viren85/movie
        // get : api/MovieInfo?movieId={id}
        protected override string ProcessRequest()
        {
            JavaScriptSerializer json = new JavaScriptSerializer();

            MovieInfo movieInfo = new MovieInfo();

            var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query);
            if (string.IsNullOrEmpty(qpParams["movieId"]))
            {
                throw new ArgumentException("movieId is not present");
            }

            string movieId = qpParams["movieId"].ToString();

            var tableMgr = new TableManager();
            var movie = tableMgr.GetMovieById(movieId);
            if (movie != null)
            {
                movieInfo.movieId = movie.MovieId;
                movieInfo.Movie = movie;

                var reviews = movie.GetReviewIds();

                var reviewList = tableMgr.GetReviewsByMovieId(movieInfo.movieId);

                List<ReviewEntity> userReviews = new List<ReviewEntity>();

                if (reviewList != null)
                {
                    foreach (var review in reviewList)
                    {
                        userReviews.Add(review.Value);
                    }
                }

                movieInfo.MovieReviews = userReviews;
            }

            return json.Serialize(movieInfo);
        }
コード例 #4
0
        // get : api/MovieInfo?q={movieId}
        protected override string ProcessRequest()
        {
            JavaScriptSerializer json = new JavaScriptSerializer();

            try
            {
                var tableMgr = new TableManager();
                MovieInfo movieInfo = new MovieInfo();

                // get query string parameters
                var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query);

                if (string.IsNullOrEmpty(qpParams["q"]))
                {
                    throw new ArgumentException(Constants.API_EXC_MOVIE_NAME_NOT_EXIST);
                }

                string name = qpParams["q"].ToString();

                // get single movie object form database by its uinque name
                var movie = tableMgr.GetMovieByUniqueName(name);

                if (movie != null)
                {
                    List<ReviewEntity> userReviews = new List<ReviewEntity>();

                    movieInfo.movieId = movie.MovieId;

                    // get reviews for movie by movie id
                    var reviewList = tableMgr.GetReviewsByMovieId(movie.MovieId);

                    if (reviewList != null)
                    {
                        // if reviews not null then add review to review list.
                        foreach (var review in reviewList)
                        {
                            ReviewerEntity reviewer = tableMgr.GetReviewerById(review.Value.ReviewerId);
                            ReviewEntity objReview = review.Value as ReviewEntity;

                            objReview.Affiliation = reviewer.Affilation;
                            objReview.ReviewerName = reviewer.ReviewerName;
                            objReview.OutLink = reviewer.ReviewerImage;
                            userReviews.Add(objReview);
                        }
                    }

                    //add reviewlist to movieinfo reviews
                    movieInfo.MovieReviews = userReviews;

                    // serialize movie object and return.
                    return json.Serialize(movieInfo);
                }
                else
                {
                    // if movie not found then return empty string
                    return string.Empty;
                }
            }
            catch (Exception ex)
            {
                // if any error occured then return User friendly message with system error message
                return json.Serialize(new { Status = "Error", UserMessage = Constants.UM_WHILE_GETTING_MOVIE, ActualError = ex.Message });
            }
        }
コード例 #5
0
        private static void UpdateLuceneIndex(MovieEntity movie)
        {
            var tableMgr = new TableManager();

            // Update Lucene
            Task.Run(() =>
            {
                //delete Entry in lucene search index
                // Fix following method call - What shall be other param?
                LuceneSearch.ClearLuceneIndexRecord(movie.MovieId, "Id");
                LuceneSearch.ClearLuceneIndexRecord(movie.UniqueName, "UniqueName");

                string posterUrl = "default-movie.jpg";
                string critics = string.Empty;

                if (!string.IsNullOrEmpty(movie.Posters))
                {
                    List<string> pList = jsonSerializer.Value.Deserialize(movie.Posters, typeof(List<string>)) as List<string>;
                    if (pList != null && pList.Count > 0)
                    {
                        posterUrl = pList.Last();
                    }
                }

                var reviewDic = tableMgr.GetReviewsByMovieId(movie.MovieId);
                if (reviewDic != null && reviewDic.Values != null && reviewDic.Values.Count > 0)
                {
                    critics = jsonSerializer.Value.Serialize(reviewDic.Values.Select(re => re.ReviewerName));
                }

                // add updated entry in lucene search index
                MovieSearchData movieSearchIndex = new MovieSearchData();
                movieSearchIndex.Id = movie.RowKey;
                movieSearchIndex.Title = movie.Name;
                movieSearchIndex.Type = movie.Genre;
                movieSearchIndex.TitleImageURL = posterUrl;
                movieSearchIndex.UniqueName = movie.UniqueName;
                movieSearchIndex.Description = movie.Cast;
                movieSearchIndex.Critics = critics;
                movieSearchIndex.Link = movie.UniqueName;

                LuceneSearch.AddUpdateLuceneIndex(movieSearchIndex);
            });
        }
コード例 #6
0
        private void BuildMovieIndex()
        {
            TableManager tblMgr = new TableManager();
            JavaScriptSerializer json = new JavaScriptSerializer();

            IDictionary<string, MovieEntity> movies = tblMgr.GetAllMovies();

            string posterUrl = string.Empty;

            foreach (MovieEntity movie in movies.Values)
            {
                List<String> posters = json.Deserialize(movie.Posters, typeof(List<String>)) as List<String>;
                List<APIRole.UDT.Cast> casts = json.Deserialize(movie.Cast, typeof(List<APIRole.UDT.Cast>)) as List<APIRole.UDT.Cast>;

                List<string> actors = new List<string>();
                List<string> critics = new List<string>();

                MovieSearchData movieSearchIndex = new MovieSearchData();
                IDictionary<string, ReviewEntity> reviews = tblMgr.GetReviewsByMovieId(movie.MovieId);

                if (posters != null && posters.Count > 0)
                {
                    posterUrl = posters[posters.Count - 1];
                }

                if (reviews != null)
                {
                    foreach (ReviewEntity review in reviews.Values)
                    {
                        if (!string.IsNullOrEmpty(review.ReviewerName))
                            critics.Add(review.ReviewerName);
                    }
                }

                if (casts != null)
                {
                    foreach (var actor in casts)
                    {
                        // actor, director, music, producer
                        string role = actor.role.ToLower();
                        string characterName = string.IsNullOrEmpty(actor.charactername) ? string.Empty : actor.charactername;

                        // Check if artist is already present in the list for some other role.
                        // If yes, skip it. Also if the actor name is missing then skip the artist
                        if (actors.Contains(actor.name) || string.IsNullOrEmpty(actor.name) || actor.name == "null")
                            continue;

                        // If we want to showcase main artists and not all, keep the following switch... case.
                        switch (role)
                        {
                            case "actor":
                                actors.Add(actor.name);
                                break;
                            case "producer":
                                // some times producer are listed as line producer etc.
                                // We are not interested in those artists as of now?! Hence skipping it
                                if (characterName == role)
                                {
                                    actors.Add(actor.name);
                                }
                                break;
                            case "music":
                            case "director":
                                // Main music director and movie director does not have associated character name.
                                // Where as other side directors have associated character name as associate director, assitant director.
                                // Skipping such cases.
                                if (string.IsNullOrEmpty(characterName))
                                {
                                    actors.Add(actor.name);
                                }
                                break;
                        }

                    }
                }

                movieSearchIndex.Id = movie.RowKey;
                movieSearchIndex.Title = movie.Name;
                movieSearchIndex.Type = movie.Genre;

                // Selected poster url
                movieSearchIndex.TitleImageURL = posterUrl;

                movieSearchIndex.UniqueName = movie.UniqueName;
                movieSearchIndex.Description = json.Serialize(actors);
                movieSearchIndex.Critics = json.Serialize(critics);
                movieSearchIndex.Link = movie.UniqueName;
                LuceneSearch.AddUpdateLuceneIndex(movieSearchIndex);
            }
        }