예제 #1
0
 public ViewUpVoteModel(UpVote vote)
     : base(vote)
 {
 }
예제 #2
0
        public ActionResult UpVote([Bind(Prefix = "id")] long postId)
        {
            Post post = dataContext.Posts.SingleOrDefault(a => a.Id == postId);
            if (post != null)
            {
                User user = ControllerHelper.GetAuthenticatedUser(dataContext);

                //Make sure that the user is not voting on their own post
                if (user != null && post.Author.OpenId != user.OpenId)
                {
                    //Make sure that the user has not voted on the post yet
                    if (post.Votes.All(a => a.Voter.OpenId != user.OpenId))
                    {
                        Vote vote = new TheFlow.Api.Entities.UpVote
                        {
                            Voter = user,
                            Post = post,
                            DateVoted = DateTime.UtcNow
                        };
                        int reputation = post.AddVote(vote);
                        vote.Value = reputation;
                        //add the reputation to the author
                        post.Author.Reputation += reputation;

                        dataContext.SaveChanges();
                    }
                    else
                    {
                        //otherwise, remove the vote.
                        return RemoveVote(postId);
                    }
                }
                else if (user == null)
                {
                    return ControllerHelper.Redirect(Url.Action("LogIn", "Users"), Request, Redirect);
                }
            }
            return Index(postId);
            //return ControllerHelper.RedirectBack(Request, Redirect, true);
        }