public async Task <IActionResult> Vote([FromRoute] string pollId) { PollRenderViewModel pollRenderViewModel = await _pollRepository.Select(pollId); int primaryKey = 0; primaryKey = await _pollRepository.SelectPollPk(pollId); pollRenderViewModel.Options = await _pollOptionRepository.Select(primaryKey); return(View("Vote", pollRenderViewModel)); }
public async Task <PollRenderViewModel> Select(string pollId) { PollRenderViewModel pollRenderViewModel = new PollRenderViewModel(); using (var command = await CreateCommand()) { try { StringBuilder sqlText = new StringBuilder(); sqlText.Append( "Select title, is_single_option, is_published, poll_id, editor_token From ct_poll "); sqlText.Append("Where poll_id = @poll_id"); command.CommandType = CommandType.Text; command.CommandText = sqlText.ToString(); command.Parameters.AddWithValue("@poll_id", pollId); using (var reader = await command.ExecuteReaderAsync()) { if (reader.HasRows) { while (reader.Read()) { if (reader.GetValue(0).ToString() == "" || reader.GetValue(1).ToString() == "") { return(null); } else { pollRenderViewModel.Title = reader.GetString(0); pollRenderViewModel.IsSingleOption = reader.GetBoolean(1); pollRenderViewModel.IsPublished = reader.GetBoolean(2); } } } else { return(null); } } command.Transaction.Commit(); } catch (SqlException) { command.Transaction.Rollback(); } } return(pollRenderViewModel); }
public async Task <IActionResult> RenderVotePage([FromRoute] string pollId) { PollDto pollDto = await _pollRepository.Select(pollId); if (pollDto == null) { return(NotFound()); } bool hasVoted = CheckIfUserHasVoted(pollId); PollRenderViewModel pollRenderViewModel = new PollRenderViewModel() { Title = pollDto.Title, IsSingleOption = Convert.ToBoolean(pollDto.IsSingleOption), Options = await _pollOptionRepository.SelectAllForPollPk(pollDto.PrimaryKey), PollId = pollDto.PollId, HasVoted = hasVoted }; return(View("RenderVotePage", pollRenderViewModel)); }