protected void Page_Load(object sender, EventArgs e) { errorPanel.Visible = false; successPanel.Visible = false; string value = Request.QueryString["value"]; if (value != null && value != string.Empty) { DAO.VotingFormBase dao = new DAO.VotingFormBase(); if (dao.DetectPoll(value)) { PollBuilding exec = new PollBuilding(); Entity.Poll poll = exec.RequestPoll(value); if (poll != null) { #region PAGE BUILD pollTitle.Text = poll.title; StringBuilder sb = new StringBuilder(); sb.Append("<div class=\"list-group\">"); foreach (Entity.Option option in poll.pollOption) { sb.Append("<button onclick=\"SendVote(this);\" id=\"" + option.idOption + "\" name=\"option\" type=\"button\" class=\"list-group-item list-group-item-action d-flex justify-content-between align-items-center\" >" + option.question); sb.Append("<span id=\"" + option.idOption + "b\" class=\"badge badge-primary badge-pill\" >" + option.votes + "</span>"); sb.Append("</button>"); } sb.Append("</div>"); litOptions.Text = sb.ToString(); successPanel.Visible = true; #endregion } else { errorMessage.Text = "Failed to create poll"; errorPanel.Visible = true; } } else { errorMessage.Text = "Poll not found"; errorPanel.Visible = true; } } else { errorMessage.Text = "Invalid value"; errorPanel.Visible = true; } }
public string BuildPoll(List <string> pollValues) { DateTime currentDate = DateTime.Now; if (currentDate != null) { Entity.Poll poll = new Entity.Poll(); poll.pollOption = new List <Entity.Option>(); poll.IdPoll = "poll" + currentDate.Ticks.ToString(); poll.title = pollValues[0]; for (int i = 1; i < pollValues.Count; i++) { Entity.Option option = new Entity.Option(); option.idOption = "option" + currentDate.Ticks.ToString() + "-" + i; option.question = pollValues[i]; poll.pollOption.Add(option); } DAO.VotingFormBase sendPoll = new DAO.VotingFormBase(); bool noErrorPoll = sendPoll.CreatePoll(poll); bool noErrorOptions = false; if (noErrorPoll) { noErrorOptions = sendPoll.CreatePollOptions(poll); } if (noErrorPoll && noErrorOptions) { return(poll.IdPoll); } } return("error"); }
public Entity.Poll RequestPoll(string idPoll) { DAO.VotingFormBase dao = new DAO.VotingFormBase(); Entity.Poll poll = new Entity.Poll(); poll.pollOption = new List <Entity.Option>(); try { #region OBJECT BUILD DataTable dt = dao.GetPoll(idPoll); poll.IdPoll = dt.Rows[0]["id_poll"].ToString(); poll.title = dt.Rows[0]["title_poll"].ToString(); dt = dao.GetOptions(idPoll); foreach (DataRow dr in dt.Rows) { Entity.Option option = new Entity.Option(); option.idOption = dr["id_option"].ToString(); option.question = dr["question"].ToString(); option.votes = (int)dr["votes"]; poll.pollOption.Add(option); } #endregion } catch (Exception ex) { return(null); } return(poll); }