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)); }
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); }
public Poll Add(Poll poll) { if (poll.Options != null) { foreach (var option in poll.Options) { option.Poll = poll; } } return(_pollRepository.Add(poll)); }
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); }
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))); }
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); }
/// <summary> /// Создание опроса /// </summary> /// <param name="dto">Временная сущность создаваемого опроса</param> /// <returns>Идентификатор созданного опроса</returns> public int CreatePollAndGetId(PollDto dto) { return(_pollRepository.Add(_mapper.Map <Poll>(dto))); }
public Poll Add(Poll poll) { poll.DateCreated = DateTime.UtcNow; poll.IsClosed = false; return(_pollRepository.Add(poll)); }
public void Add(Poll entity) { _pollRepository.Add(entity); }