示例#1
0
        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();
            }
        }
示例#2
0
        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");
        }
示例#3
0
        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);
        }