Exemple #1
0
        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;
        }
        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
                  });
            }
        }