Пример #1
0
 public ViewDownVoteModel(DownVote vote)
     : base(vote)
 {
 }
Пример #2
0
        public ActionResult DownVote([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.DownVotes.All(a => a.Voter.OpenId != user.OpenId))
                    {
                        Vote vote = new TheFlow.Api.Entities.DownVote
                        {
                            Voter = user,
                            Post = post,
                            DateVoted = DateTime.UtcNow
                        };
                        int rep = post.AddVote(vote);
                        vote.Value = rep;
                        post.Author.Reputation += rep;
                        dataContext.SaveChanges();
                    }
                }
                else if (user == null)
                {
                    return ControllerHelper.Redirect(Url.Action("LogIn", "Users"), Request, Redirect);
                }
            }
            return Index(postId);
        }