Esempio n. 1
0
        public ActionResult Show(long pollId, [FromQuery] bool embed = false)
        {
            Polls poll = _db.Polls.Find(pollId);

            if (poll == null)
            {
                return(Content("Poll not found"));
            }

            if (poll.ImageId != null)
            {
                ViewData["PollImage"] = _db.PollImages.Find(poll.ImageId);
            }

            if (0 == poll.HideLink2pollOwner)
            {
                ViewData["PollCreator"] = _db.Users.Find(poll.MemberId);
            }

            if (poll.AllowMultipleSelections > 0)
            {
                ViewBag.UriForVote     = string.Format("{0}://{1}/vote/multiple/{2}", Request.Scheme, Request.Host, poll.Id);
                ViewData["VotesCount"] = _db.PollVotes2.Count(v2 => v2.PollId == pollId);
            }
            else
            {
                long [] choices =
                    _db.PollChoices.Where(c => c.PollId == pollId)
                    .Select(c => c.Id)
                    .ToArray();

                ViewBag.UriForVote     = string.Format("{0}://{1}/vote/single/{2}", Request.Scheme, Request.Host, poll.Id);
                ViewData["VotesCount"] = _db.PollVotes1.Count(v1 => choices.Contains(v1.PollChoiceId));
            }

            if (poll.HideVotingResults > 0)
            {
                ViewData["ShouldSeeResults"] = false;
            }
            else if (poll.Status == (long)PollStatus.Closed)
            {
                ViewData["ShouldSeeResults"] = (poll.ShowResultsWhenClosed > 0);
            }
            else
            {
                ViewData["ShouldSeeResults"] = true;
            }

            ViewData["Choices"] = _db.GetPollChoices(pollId);

            if (embed)
            {
                ViewBag.UriForPoll = string.Format("{0}://{1}/polls/show/{2}", Request.Scheme, Request.Host, poll.Id);
                return(View("ShowEmbedded", poll));
            }

            ViewData["PollTopic"] = _db.PollTopics.Find(poll.PollTopicId);
            return(View(poll));
        }