protected void Page_Load(object sender, EventArgs e) { errorPanel.Visible = false; string value; try { value = Request.QueryString["value"]; } catch (Exception ex) { Response.ClearHeaders(); Response.Write("<h2 class=\"display - 4\">Request Block</h1>"); Response.End(); value = string.Empty; } if (value != null && value != string.Empty) { Entity.Option option = new Entity.Option(); DAO.VotingFormBase dao = new DAO.VotingFormBase(); option.idOption = value; option.votes = dao.GetVotesOption(value); string jsonObject = JsonConvert.SerializeObject(option); Response.Clear(); Response.ContentType = "application/json"; Response.Write(jsonObject); Response.End(); } }
protected void Page_Load(object sender, EventArgs e) { string value = Request.Form["value"]; if (value != null && value != string.Empty) { string userIp = string.Empty; if (HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] != null) { userIp = HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString(); } else if (HttpContext.Current.Request.UserHostAddress.Length != 0) { userIp = HttpContext.Current.Request.UserHostAddress; } int index = userIp.IndexOf(':'); if (index > 0) { userIp = userIp.Substring(0, index); } DAO.VotingFormBase dao = new DAO.VotingFormBase(); if (dao.CheckIP(userIp, value)) { dao.SendVote(value); dao.SendIP(userIp, value); } } }
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); }