Exemple #1
0
        public async Task <ActionResult> PollDetail(string pollid)
        {
            var poll = await pollDac.GetPoll(pollid);

            var choices = await choiceDac.GetChoiceByPollId(poll.Id);

            var ch = choices.Select(it => {
                var rate = it.Votes != null && it.Votes.Any() ? (int)Math.Round(it.Votes.Sum(v => v.Rating) / it.Votes.Count()) : 0;
                return(new ChoiceInformation
                {
                    PollRefId = poll.Id,
                    Name = it.Title,
                    Rate = rate,
                    Id = it.Id
                });
            });

            var pollInfo = new PollInformation
            {
                Id         = poll.Id,
                Name       = poll.Topic,
                OwnerName  = poll.Owner,
                CreateDate = poll.CreateAt,
                Choices    = ch
            };

            return(View(pollInfo));
        }
Exemple #2
0
        public async Task <ActionResult> Polls()
        {
            var polls = await pollDac.GetPolls();

            var model = new List <PollInformation>();

            foreach (var poll in polls)
            {
                var choices = await choiceDac.GetChoiceByPollId(poll.Id);

                var ch = choices.Select(it => new ChoiceInformation
                {
                    PollRefId = poll.Id,
                    Name      = it.Title
                });

                var pollInfo = new PollInformation
                {
                    Id         = poll.Id,
                    Name       = poll.Topic,
                    OwnerName  = poll.Owner,
                    CreateDate = poll.CreateAt,
                    Choices    = ch
                };

                model.Add(pollInfo);
            }
            return(View(model));
        }
Exemple #3
0
        public async Task <ActionResult> CreatePoll(PollInformation model)
        {
            var id = Guid.NewGuid().ToString();
            await pollDac.CreatePoll(new Poll
            {
                Id       = id,
                Topic    = model.Name,
                Owner    = User.Identity.Name,
                CreateAt = DateTime.UtcNow
            });

            return(RedirectToAction(nameof(PollDetail), new { pollid = id }));
        }