Esempio n. 1
0
        public ActionResult showResults(string guid)
        {
            PollQuestion p = pollRepository.GetPollByGUID(guid);

            if (p == null || !p.Active)
                return View(HttpNotFound());

            PollVoteModel model = new PollVoteModel() {
            poll = p,
            selectedID = voteRepository.getVotedAnswerID(WebSecurity.CurrentUserId,p.ID),
            };

            return View(model);
        }
Esempio n. 2
0
        public ActionResult showPoll(string guid, PollVoteModel model)
        {
            PollQuestion p = pollRepository.GetPollByGUID(guid);

            if (p == null || !p.Active)
                return View(HttpNotFound());

            if (pollRepository.userVoted(WebSecurity.CurrentUserId, p.ID))
                return RedirectToAction("showResults", new { guid=guid });

            if (ModelState.IsValid)
            {
                int selectedAnswer = model.selectedID;
                PollVote pv = new PollVote() { Poll = p, Answer = pollRepository.GetAnswerbyID(selectedAnswer), UserId = WebSecurity.CurrentUserId};
                voteRepository.InsertVote(pv);
                voteRepository.Save();
                if (!WebSecurity.IsAuthenticated)
                {
                    Session.Timeout = 1440;
                    Session["votedPoll" + p.ID] = p;
                }
                return RedirectToAction("showResults", new { guid = guid });
            }

            model.poll = p;
            //voteRepository.userVoted(p.ID, WebSecurity.GetUserId(User.Identity.Name)) || Session["votedPoll" + p.ID] != null;

            return View(model);
        }