Пример #1
0
        public async Task <ActionResult <PollCreatedViewModel> > CreatePoll([FromBody] PollCreationModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var(code, codeHash) = _pollService.GenerateSecretCode();
            var poll = new Poll
            {
                Id                      = Guid.NewGuid(),
                Question                = model.Question,
                CreatedOn               = DateTime.Now,
                Duration                = model.Duration.HasValue ? TimeSpan.FromSeconds(model.Duration.Value) : default(TimeSpan?),
                IsPublic                = model.IsPublic,
                SecretCodeHash          = codeHash,
                AllowMultipleVotesPerIp = model.AllowMultipleVotesPerIp,
                Answers                 = model.Answers.Select(a => new Answer
                {
                    Id      = Guid.NewGuid(),
                    Content = a.Content,
                    Votes   = new List <Vote>()
                }).ToList()
            };

            await _pollRepository.Add(poll);

            var output = new PollCreatedViewModel
            {
                PollId     = poll.Id.ToString(),
                SecretCode = code
            };

            return(Ok(output));
        }
Пример #2
0
        public async Task <IActionResult> AddPoll([Bind("Que,Opt")] Poll poll)
        {
            if (ModelState.IsValid)
            {
                string   userid = context.ApplicationUsers.Single(au => au.Email == User.Identity.Name).Id;
                int      nopt;
                string[] options = poll.Opt.Split(",");
                nopt = options.Length;
                string votes = "";
                for (int i = 0; i < nopt - 1; i++)
                {
                    votes += "0,";
                }
                votes      += "0";
                poll.UserId = userid;
                poll.Votes  = votes;
                poll.Date   = DateTime.Now;
                await _pollRepo.Add(poll);

                return(RedirectToAction(nameof(Index)));
            }
            else
            {
                return(RedirectToAction(nameof(AddPoll)));
            }
        }
        public async Task <Poll> Adicionar(Poll poll)
        {
            var caunt = 1;

            if (poll.Id == 0)
            {
                poll.Id = _pollRepository.GetAll().Result
                          .Count() == 0 ? 1 : _pollRepository.GetAll().Result.Count() + 1;
            }

            foreach (var opcao in poll.Options.ToList())
            {
                opcao.Id = caunt;
                caunt++;
            }

            if (!ExecutarValidacao(new PollValidation(), poll))
            {
                return(null);
            }

            await _pollRepository.Add(poll);

            return(poll);
        }
Пример #4
0
        public Poll Add(Poll poll)
        {
            if (poll.Options != null)
            {
                foreach (var option in poll.Options)
                {
                    option.Poll = poll;
                }
            }

            return(_pollRepository.Add(poll));
        }
Пример #5
0
        public int SavePoll(PollOptionsJsonVM pollOptions)
        {
            var poll = _pollRepository.Add(new Poll(pollOptions.Poll_description, 0));

            foreach (var item in pollOptions.options)
            {
                var optionId = _optionService.SaveOption(new OptionVM(item));
                _pollOptionService.SavePollOption(poll.PollId, optionId);
            }

            return(poll.PollId);
        }
Пример #6
0
        public Task <GetPollIdQueryModel> Handle(AddPollCommand request, CancellationToken cancellationToken)
        {
            var poll = _pollRepository.Add(CreateModelToCommand(request));

            _pollRepository.UnitOfWork.Salvar();

            if (poll is null)
            {
                return(null);
            }

            return(Task.FromResult(new GetPollIdQueryModel(poll.Id)));
        }
Пример #7
0
        public IActionResult CreatePoll(Poll poll)
        {
            IActionResult result = View();

            if (!_userRepository.IsLogged())
            {
                return(NotFound());
            }
            if (ModelState.IsValid)
            {
                poll.CreatorLogin = _userRepository.GetCurrentUser().Login;
                poll.Questions    = new List <Question>
                {
                    new Question
                    {
                        PossibleAnswers = new List <Answer>
                        {
                            new Answer(), new Answer(), new Answer()
                        }
                    },
                    new Question
                    {
                        PossibleAnswers = new List <Answer>
                        {
                            new Answer(), new Answer(), new Answer()
                        }
                    }
                };

                var newPoll = _pollRepository.Add(poll);
                HttpContext.Session.Put("poll", newPoll);
                result = RedirectToAction("EditPoll");
            }

            return(result);
        }
Пример #8
0
 /// <summary>
 /// Создание опроса
 /// </summary>
 /// <param name="dto">Временная сущность создаваемого опроса</param>
 /// <returns>Идентификатор созданного опроса</returns>
 public int CreatePollAndGetId(PollDto dto)
 {
     return(_pollRepository.Add(_mapper.Map <Poll>(dto)));
 }
Пример #9
0
 public Poll Add(Poll poll)
 {
     poll.DateCreated = DateTime.UtcNow;
     poll.IsClosed    = false;
     return(_pollRepository.Add(poll));
 }
Пример #10
0
 public void Add(Poll entity)
 {
     _pollRepository.Add(entity);
 }