/// <summary> /// Update the reviewer by reviewerid /// </summary> /// <param name="store"></param> /// <param name="reviewer"></param> /// <returns></returns> public static bool UpdateReviewerById(this IStore store, ReviewerEntity reviewer) { Debug.Assert(reviewer != null); var list = new List <ReviewerEntity> { reviewer }; var retList = store.UpdateReviewers(list); Debug.Assert(retList.Count == 1); return(retList[retList.Keys.FirstOrDefault()]); }
public static string SetReviewer(string reviewerName, string affiliation) { string reviewerKey = string.Empty; try { #region Add Reviewer In DB TableManager tblMgr = new TableManager(); ReviewerEntity reviewer = new ReviewerEntity(); bool isReviewerAlreadyPresent = false; var reviewers = tblMgr.GetAllReviewer(); for (int rid = 0; rid < reviewers.Keys.Count; rid++) { string key = reviewers.ElementAt(rid).Key; if (reviewers[key].ReviewerName.Trim() == reviewerName.Trim()) { isReviewerAlreadyPresent = true; reviewerKey = key; break; } } if (!isReviewerAlreadyPresent) { reviewer.RowKey = reviewer.ReviewerId = Guid.NewGuid().ToString(); reviewer.ReviewerName = reviewerName.Trim(); reviewer.Affilation = affiliation.Trim(); reviewer.ReviewerImage = string.Empty; tblMgr.UpdateReviewerById(reviewer); reviewerKey = reviewer.ReviewerId; } #endregion } catch (Exception) { } return(reviewerKey); }
// 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 })); } }
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); }
protected override string ProcessRequest() { JavaScriptSerializer json = new JavaScriptSerializer(); try { var tableMgr = new TableManager(); // get query string parameters var qpParams = HttpUtility.ParseQueryString(this.Request.RequestUri.Query); if (string.IsNullOrEmpty(qpParams["d"])) { //throw new ArgumentException(Constants.API_EXC_SEARCH_TEXT_NOT_EXIST); return(json.Serialize(new { Status = "Error", Message = Constants.API_EXC_SEARCH_TEXT_NOT_EXIST })); } string userId = qpParams["u"]; string cFavoriteId = qpParams["c"]; string favorites = qpParams["d"]; List <PopularOnMovieMirchiEntity> popularOnMovieMirchi = json.Deserialize(favorites, typeof(List <PopularOnMovieMirchiEntity>)) as List <PopularOnMovieMirchiEntity>; if (popularOnMovieMirchi != null) { foreach (PopularOnMovieMirchiEntity objPopular in popularOnMovieMirchi) { PopularOnMovieMirchiEntity oldObjPopular = tableMgr.GetPopularOnMovieMirchiById(objPopular.Name + "=" + objPopular.Type); // If the type = Actor - need to update the record if (objPopular.Type.ToLower() == "actor") { // update the popularity count ArtistEntity artist = tableMgr.GetArtist(objPopular.Name); if (artist == null) { continue; } artist.Popularity = (int.Parse(artist.Popularity) + 1).ToString(); tableMgr.UpdateArtistById(artist); } else if (objPopular.Type.ToLower() == "critics") { // update the critics popularity count - We don't have column for storing popularity of critics // Hence currently it is getting stored inside reviewer image. We are not storing reviewer image in this table ReviewerEntity reviewer = tableMgr.GetReviewerById(objPopular.Name); if (reviewer == null) { continue; } if (string.IsNullOrEmpty(reviewer.ReviewerImage)) { reviewer.ReviewerImage = "0"; } reviewer.ReviewerImage = (int.Parse(reviewer.ReviewerImage) + 1).ToString(); tableMgr.UpdateReviewerById(reviewer); } else if (objPopular.Type.ToLower() == "rate") { // update users table - save the site rating UserEntity ue = tableMgr.GetUserById(userId); if (ue == null) { continue; } ue.SiteFeedbackScore = objPopular.Name; tableMgr.UpdateUserById(ue); } /*if (oldObjPopular == null && objPopular.Type.ToLower() != "rate") * { * objPopular.PopularOnMovieMirchiId = Guid.NewGuid().ToString(); * objPopular.RowKey = objPopular.Name + "=" + objPopular.Type; * objPopular.Counter = 1; * objPopular.DateUpdated = DateTime.Now.ToString(); * * tableMgr.UpdatePopularOnMovieMirchiId(objPopular); * } * else if (objPopular.Type.ToLower() != "rate") * { * oldObjPopular.Counter = oldObjPopular.Counter + 1; * objPopular.DateUpdated = DateTime.Now.ToString(); * tableMgr.UpdatePopularOnMovieMirchiId(oldObjPopular); * }*/ } } // User Id must be present - Fav id not present = create // USer id present - fav id present - update /*if (string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(cFavoriteId)) * { * UserFavoriteEntity userFavorite = new UserFavoriteEntity(); * userFavorite.RowKey = userFavorite.UserFavoriteId = Guid.NewGuid().ToString(); * userFavorite.UserId = ""; * userFavorite.Favorites = favorites; * userFavorite.DateCreated = DateTime.Now.ToString(); * * tableMgr.UpdateUserFavoriteById(userFavorite); * * return json.Serialize(new { Status = "Ok", Message = "Set Cookie", FavoriteId = userFavorite.UserFavoriteId }); * } * else */ if (!string.IsNullOrEmpty(userId) && userId.ToLower() != "undefined" && !string.IsNullOrEmpty(cFavoriteId)) { UserFavoriteEntity userFavorite = tableMgr.GetUserFavoritesByUserId(userId); if (userFavorite == null) { userFavorite = tableMgr.GetUserFavoriteById(cFavoriteId); if (userFavorite != null) { userFavorite.UserId = userId; userFavorite.Favorites = favorites; userFavorite.DateCreated = DateTime.Now.ToString(); tableMgr.UpdateUserFavoriteById(userFavorite); } } else { userFavorite.Favorites = favorites; userFavorite.DateCreated = DateTime.Now.ToString(); tableMgr.UpdateUserFavoriteById(userFavorite); } return(json.Serialize(new { Status = "Ok", Message = "Updated" })); } else if (!string.IsNullOrEmpty(userId) && string.IsNullOrEmpty(cFavoriteId)) { UserFavoriteEntity userFavorite = tableMgr.GetUserFavoritesByUserId(userId); if (userFavorite != null) { userFavorite.Favorites = favorites; userFavorite.DateCreated = DateTime.Now.ToString(); tableMgr.UpdateUserFavoriteById(userFavorite); return(json.Serialize(new { Status = "Ok", Message = "Updated" })); } } return(json.Serialize(new { Status = "Error", Message = "No Updated" })); } catch (Exception ex) { // if any error occured then return User friendly message with system error message return(json.Serialize( new { Status = "Error", UserMessage = "Unable to save your favorites. Please try again later.", ActualError = ex.Message })); } }