Esempio n. 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 = "" });
            }
        }
Esempio n. 2
0
        public ActionResult Search(string q)
        {
            var connectionString = CloudConfigurationManager.GetSetting("StorageTableConnectionString");
            Trace.TraceInformation("Connection str read");
            ConnectionSettingsSingleton.Instance.StorageConnectionString = connectionString;

            if (string.IsNullOrWhiteSpace(q))
            {
                q = "testsample";
            }
            var tableMgr = new TableManager();
            var movie = tableMgr.GetMovieById(q);

            var resp = new StringBuilder();
            if (movie != null)
            {
                resp.Append("Movie Name : ");
                resp.Append(movie.Name);

                var reviews = movie.GetReviewIds();
                var reviewList = tableMgr.GetReviewsById(reviews);
                foreach (var reviewEntity in reviewList)
                {
                    resp.Append("\r\n With review -- ");
                    resp.Append(reviewEntity.Value.Review);
                }
            }
            else
            {
                resp.Append("No movie found");
            }

            ViewBag.Message = "You searched for " + q + "and the response you got was: " + resp;

            return View();
        }
        // get : api/ReviewerInfo?name={id}
        protected override string ProcessRequest()
        {
            string name = "";

            try
            {
                var tableMgr = new TableManager();

                Reviewer reviewerInfo = new Reviewer();
                List<ReviewDetails> reviewDetailList = new List<ReviewDetails>();

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

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

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

                if (!DataStoreLib.Utils.CacheManager.TryGet<Reviewer>(CacheConstants.ReviewerMoviesEntity + name.Replace(" ", "-").ToLower().Trim(), out reviewerInfo))
                {
                    reviewerInfo = new Reviewer();
                    reviewDetailList = new List<ReviewDetails>();

                    // getting reviewer details
                    var reviews = tableMgr.GetReviewsByReviewer(name);

                    if (reviews != null && reviews.Count > 0)
                    {
                        int courter = 0;

                        foreach (ReviewEntity review in reviews.Values)
                        {
                            if (courter == 0)
                            {
                                // getting reviewer Informations
                                reviewerInfo.Affilation = review.Affiliation;
                                reviewerInfo.Name = review.ReviewerName;
                                reviewerInfo.OutLink = review.OutLink;
                            }
                            else if (review.MovieId == null)
                                continue;

                            // get movie information
                            MovieEntity movie = tableMgr.GetMovieById(review.MovieId);

                            if (movie != null && (movie.State == "upcoming" || movie.State == "now-playing" || movie.State == "released" || movie.State == "now playing" || movie.State == ""))
                            {
                                // if movie not null, then add movieid and moviename to review details
                                ReviewDetails reviewDetail = new ReviewDetails();
                                reviewDetail.CriticsRating = review.SystemRating == 0 ? "" : (review.SystemRating == -1 ? 0 : 100).ToString();
                                reviewDetail.MovieId = movie.MovieId;
                                reviewDetail.MovieName = movie.Name;
                                reviewDetail.Review = review.Review;
                                reviewDetail.MoviePoster = movie.Posters;
                                reviewDetail.OutLink = review.OutLink;
                                reviewDetail.Tags = review.Tags;
                                reviewDetail.MovieStatus = movie.State;

                                // add review object to review list
                                reviewDetailList.Add(reviewDetail);
                            }

                            courter++;
                        }

                        // add reviewList to reviewInfoObject
                        reviewerInfo.ReviewsDetails = reviewDetailList;

                        DataStoreLib.Utils.CacheManager.Add<Reviewer>(CacheConstants.ReviewerMoviesEntity + name.Replace(" ", "-").ToLower().Trim(), reviewerInfo);
                    }
                    else
                    {
                        return jsonSerializer.Value.Serialize(
                      new
                      {
                          Status = "Error",
                          UserMessage = "Currently Movie Mirchi does not have any information about this critic (" + name + ")",
                          ActualError = string.Empty
                      });
                    }
                }

                // serialize and return reviewer details along with reviews
                return jsonSerializer.Value.Serialize(reviewerInfo);
            }
            catch (Exception ex)
            {
                // if any error occured then return User friendly message with system error message
                return jsonSerializer.Value.Serialize(
                  new
                  {
                      Status = "Error",
                      UserMessage = "Unable to get reviewer " + name + "'s details.",
                      ActualError = ex.Message
                  });
            }
        }
Esempio n. 4
0
        internal static string SetReviewAndUpdateMovieRating(string movieId, string reviewId, int rating, string bag)
        {
            var tableMgr = new TableManager();
            MovieEntity movie = tableMgr.GetMovieById(movieId);

            if (movie != null)
            {
                ReviewEntity review = tableMgr.GetReviewById(reviewId);

                if (review != null)
                {
                    // -1 => Negative
                    //  0 => No rating
                    // +1 => Positive
                    rating = (rating < 0) ? -1 : 1;

                    review.SystemRating = rating;
                    tableMgr.UpdateReviewById(review);

                    string myscore = movie.MyScore;
                    if (string.IsNullOrEmpty(myscore) || myscore == "0")
                    {
                        myscore = "{\"teekharating\":\"0\",\"feekharating\":\"0\",\"criticrating\":\"\"}";
                    }

                    RatingConvertion newRating = new RatingConvertion();
                    RatingConvertion oldRating;
                    try
                    {
                        oldRating = jsonSerializer.Value.Deserialize(myscore, typeof(RatingConvertion)) as RatingConvertion;
                    }
                    catch
                    {
                        myscore = "{\"teekharating\":\"0\",\"feekharating\":\"0\",\"criticrating\":\"\"}";
                        oldRating = jsonSerializer.Value.Deserialize(myscore, typeof(RatingConvertion)) as RatingConvertion;
                    }

                    var teekha = oldRating.teekharating + (rating > 0 ? 1 : 0);
                    var feekha = oldRating.feekharating + (rating < 0 ? 1 : 0);
                    newRating.teekharating = teekha;
                    newRating.feekharating = feekha;
                    newRating.criticrating = ((int)(teekha / (double)(teekha + feekha) * 100)).ToString();

                    string strNewRating = jsonSerializer.Value.Serialize(newRating);
                    movie.Rating = newRating.criticrating;
                    movie.MyScore = strNewRating;
                    tableMgr.UpdateMovieById(movie);

                    return jsonSerializer.Value.Serialize(new { Status = "Ok", UserMessage = "Successfully update movie rating" });
                }
                else
                {
                    return jsonSerializer.Value.Serialize(new { Status = "Error", UserMessage = "Unable to find review with passed review id. Please check review id." });
                }
            }
            else
            {
                return jsonSerializer.Value.Serialize(new { Status = "Error", UserMessage = "Unable to find movie with passed movie id. Please check movie id." });
            }
        }
Esempio n. 5
0
        // 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);
        }
Esempio n. 6
0
        // get : api/ReviewerInfo?name={id}
        protected override string ProcessRequest()
        {
            JavaScriptSerializer json = new JavaScriptSerializer();

            Reviewer reviewerInfo = new Reviewer();

            List<ReviewDetails> reviewDetailList = new List<ReviewDetails>();

            try
            {
                var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query);

                if (string.IsNullOrEmpty(qpParams["name"]))
                {
                    throw new ArgumentException("name is not present");
                }

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

                var tableMgr = new TableManager();
                var reviews = tableMgr.GetReviewsByReviewer(name);

                if (reviews != null)
                {
                    int courter = 0;

                    foreach (ReviewEntity review in reviews.Values)
                    {
                        if (courter == 0)
                        {
                            reviewerInfo.Affilation = review.Affiliation;
                            reviewerInfo.Name = review.ReviewerName;
                            reviewerInfo.OutLink = review.OutLink;
                        }

                        MovieEntity movie = tableMgr.GetMovieById(review.MovieId);

                        if (movie != null)
                        {
                            ReviewDetails reviewDetail = new ReviewDetails();
                            reviewDetail.CriticsRating = review.ReviewerRating;
                            reviewDetail.MovieId = movie.MovieId;
                            reviewDetail.MovieName = movie.Name;
                            reviewDetail.Review = review.Review;

                            reviewDetailList.Add(reviewDetail);
                        }

                        courter++;
                    }
                }

                reviewerInfo.ReviewsDetails = reviewDetailList;

                return json.Serialize(reviewerInfo);

            }
            catch (Exception ex)
            {
                return json.Serialize(new { Error = "There are some error!", ActualError = ex.Message });
            }
        }