예제 #1
0
        public virtual ActionResult ArticleDetails(long articleId)
        {
            ActionResult returnValue = null;

            if (!ProviderArticle.Exists(articleId))
            {
                returnValue = RedirectToAction(MVC.Error.Index(404));
            }
            else
            {
                ProviderArticle anArticle = new ProviderArticle(articleId);

                if (anArticle.IsPublished || ProviderCurrentMember.Instance.CanEdit(anArticle))
                {
                    // increment view count and don't update edit date when saving article
                    anArticle.ViewCount += 1;
                    anArticle.Save();

                    // Send a shadow vote
                    ProviderArticleVote shadowVote = new ProviderArticleVote();
                    shadowVote.IsShadowVote = true;
                    shadowVote.ArticleId = anArticle.Id.Value;
                    shadowVote.Save();

                    returnValue = View(new DetailsVM(anArticle, ProviderCurrentMember.Instance));
                }
                else
                {
                    returnValue = RedirectToAction(MVC.Error.Index(404));
                }
            }

            return returnValue;
        }
예제 #2
0
        public virtual JsonResult Vote(long articleId, long voteValue)
        {
            // direction: true = vote up, false = vote down

            AjaxReturnMsgVM viewModel = new AjaxReturnMsgVM
            {
                StatusCode = AjaxReturnMsgVM.Status.failure,
                StatusMessage = string.Empty,
                Content = string.Empty
            };

            ProviderCurrentMember currentMember = ProviderCurrentMember.Instance;

            if ( !currentMember.IsLoggedOn )
            {
                viewModel.StatusCode = AjaxReturnMsgVM.Status.failure;
                viewModel.Content = "You must be logged on to vote.";
            }
            else if (!ProviderArticle.Exists(articleId))
            {
                viewModel.StatusCode = AjaxReturnMsgVM.Status.failure;
                viewModel.Content = "The article you voted on no longer exists.";
            }
            else if(ProviderArticleVote.HasVoted(articleId, currentMember.Id.Value))
            {
                viewModel.StatusCode = AjaxReturnMsgVM.Status.failure;
                viewModel.Content = "You have already voted on this article.";
            }
            else
            {
                ProviderArticleVote aVote = new ProviderArticleVote();
                aVote.ArticleId = articleId;
                aVote.MemberId = currentMember.Id.Value;
                aVote.IsUpVote = voteValue > 0;
                aVote.IsDownVote = voteValue < 0;
                aVote.Save();

                ProviderArticle anArticle = new ProviderArticle(articleId);
                viewModel.StatusCode = AjaxReturnMsgVM.Status.success;
                viewModel.Content = InsideWordUtility.FormatVotes(anArticle.CountVotes);
                ProviderMember author = anArticle.Author;
                if (aVote.IsUpVote &&
                    author != null &&
                    author.Id != currentMember.Id &&
                    author.HasValidAltId(ProviderAlternateMemberId.AlternateType.Email))
                {
                    // do some calculations to determine if we should send the e-mail
                    int voteCount = anArticle.CountVotes;
                    int n = (int)Math.Log((double)voteCount, 2);
                    if (n < 0) { n = 0; }
                    if (voteCount % (1 << n) == 0)
                    {
                        EmailManager.Instance.SendVoteNotificationEmail(author.Emails[0].Email, anArticle);
                    }
                }
            }

            return Json(viewModel);
        }