Exemplo n.º 1
0
        protected void OnLinkButtonDeleteAnswer_Command(object sender, CommandEventArgs e)
        {
            var dbContext = new PollSystemEntities();
            int answerId  = Convert.ToInt32(e.CommandArgument);
            var answer    = dbContext.Answers.Find(answerId);

            if (answer != null)
            {
                try
                {
                    dbContext.Answers.Remove(answer);
                    dbContext.SaveChanges();

                    ErrorSuccessNotifier.AddSuccessMessage("Answer successfully deleted");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex.Message);
                }
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("This answer does not exist anymore");
            }
        }
Exemplo n.º 2
0
        protected void OnBtnSaveChanges_Click(object sender, EventArgs e)
        {
            var dbContext  = new PollSystemEntities();
            int questionId = Convert.ToInt32(Request.Params["questionId"]);
            var question   = dbContext.Questions.Find(questionId);

            if (question != null)
            {
                try
                {
                    string questionText = this.TextBoxQuestionText.Text;
                    question.Text = questionText;
                    dbContext.SaveChanges();

                    ErrorSuccessNotifier.AddSuccessMessage("Question successfully edited");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("This question does not exist anymore");
            }
        }
Exemplo n.º 3
0
        protected void OnLinkButtonDeleteQuestion_Command(object sender, CommandEventArgs e)
        {
            var dbContext  = new PollSystemEntities();
            int questionId = Convert.ToInt32(e.CommandArgument);
            var question   = dbContext.Questions.Find(questionId);

            if (question != null)
            {
                try
                {
                    var answers = question.Answers.ToList();
                    foreach (var answer in answers)
                    {
                        dbContext.Answers.Remove(answer);
                    }

                    dbContext.Questions.Remove(question);
                    dbContext.SaveChanges();

                    this.GridViewQuestions.PageIndex = 0;
                    ErrorSuccessNotifier.AddSuccessMessage("Question successfully deleted");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex.Message);
                }
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("This question does not exist anymore");
            }
        }
        public IQueryable <Question> GridViewAllQuestions_GetData()
        {
            var context   = new PollSystemEntities();
            var questions = context.Questions.OrderBy(q => q.Text);

            return(questions);
        }
        protected void LinkButtonSaveQuestion_Click(object sender, EventArgs e)
        {
            using (var context = new PollSystemEntities())
            {
                string   questionIdStr = Request.Params["questionId"];
                Question question;
                if (string.IsNullOrEmpty(questionIdStr))
                {
                    question = new Question();
                    context.Questions.Add(question);
                }
                else
                {
                    int questionId = Convert.ToInt32(questionIdStr);
                    question = context.Questions.FirstOrDefault(x => x.QuestionId == questionId);
                }

                question.Text = this.TextBoxQuestionText.Text;

                try
                {
                    context.SaveChanges();
                    Response.Redirect("EditQuestions.aspx", false);
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
        protected void LinkButtonSaveQuestion_Click(object sender, EventArgs e)
        {
            using (var context = new PollSystemEntities())
            {
                string questionIdStr = Request.Params["questionId"];
                Question question;
                if (string.IsNullOrEmpty(questionIdStr))
                {
                    question = new Question();
                    context.Questions.Add(question);
                }
                else
                {
                    int questionId = Convert.ToInt32(questionIdStr);
                    question = context.Questions.FirstOrDefault(x => x.QuestionId == questionId);
                }

                question.Text = this.TextBoxQuestionText.Text;

                try
                {
                    context.SaveChanges();
                    Response.Redirect("EditQuestions.aspx", false);
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
Exemplo n.º 7
0
        public IQueryable <PollSystem.Models.Question> GridViewQuestions_GetData()
        {
            var dbContext = new PollSystemEntities();
            var questions = dbContext.Questions
                            .Include("Answers").OrderBy(q => q.Text);

            return(questions);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var context = new PollSystemEntities();
            var questions = context.Questions.Take(3);
            this.ListViewQuestions.DataSource = questions.ToList();

            this.DataBind();
        }
Exemplo n.º 9
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var dbContext = new PollSystemEntities();
            var questions = dbContext.Questions
                            .Include("Answers").OrderBy(q => Guid.NewGuid()).Take(3);

            this.ListViewPollQuestions.DataSource = questions.ToList();
            this.DataBind();
        }
Exemplo n.º 10
0
        protected void Page_Load(object sender, EventArgs e)
        {
            var context   = new PollSystemEntities();
            var questions = context.Questions.Take(3);

            this.ListViewQuestions.DataSource = questions.ToList();

            this.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int questionId = Convert.ToInt32(Request.Params["questionId"]);
            var context = new PollSystemEntities();
            var question = context.Questions.FirstOrDefault(x => x.QuestionId == questionId);

            this.LiteralQuestion.Text = question.Text;
            this.RepeaterAnswerResult.DataSource = question.Answers.ToList();
            this.DataBind();
        }
Exemplo n.º 12
0
        protected void LinkButtonVote_Command(object sender, CommandEventArgs e)
        {
            int answerId = Convert.ToInt32(e.CommandArgument);
            var context = new PollSystemEntities();
            Answer answer = context.Answers.Find(answerId);
            answer.Votes++;
            context.SaveChanges();

            Response.Redirect("VotingResults.aspx?questionId=" + answer.QuestionId);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            int questionId = Convert.ToInt32(Request.Params["questionId"]);
            var context    = new PollSystemEntities();
            var question   = context.Questions.FirstOrDefault(x => x.QuestionId == questionId);

            this.LiteralQuestion.Text            = question.Text;
            this.RepeaterAnswerResult.DataSource = question.Answers.ToList();
            this.DataBind();
        }
Exemplo n.º 14
0
        protected void LinkButtonVote_Command(object sender, CommandEventArgs e)
        {
            int    answerId = Convert.ToInt32(e.CommandArgument);
            var    context  = new PollSystemEntities();
            Answer answer   = context.Answers.Find(answerId);

            answer.Votes++;
            context.SaveChanges();

            Response.Redirect("VotingResults.aspx?questionId=" + answer.QuestionId);
        }
 protected void Page_PreRender(object sender, EventArgs e)
 {
     string questionIdStr = Request.Params["questionId"];
     if (!string.IsNullOrEmpty(questionIdStr))
     {
         int questionId = Convert.ToInt32(questionIdStr);
         using (var context = new PollSystemEntities())
         {
             Question question = context.Questions.FirstOrDefault(x => x.QuestionId == questionId);
             this.TextBoxQuestionText.Text = question.Text;
             this.RepeaterAnswerResult.DataSource = question.Answers.ToList();
             this.RepeaterAnswerResult.DataBind();
         }
     }
 }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            string questionIdStr = Request.Params["questionId"];

            if (!string.IsNullOrEmpty(questionIdStr))
            {
                int questionId = Convert.ToInt32(questionIdStr);
                using (var context = new PollSystemEntities())
                {
                    Question question = context.Questions.FirstOrDefault(x => x.QuestionId == questionId);
                    this.TextBoxQuestionText.Text        = question.Text;
                    this.RepeaterAnswerResult.DataSource = question.Answers.ToList();
                    this.RepeaterAnswerResult.DataBind();
                }
            }
        }
 // The id parameter name should match the DataKeyNames value set on the control
 public void GridViewQuestions_DeleteItem(int questionId)
 {
     var context = new PollSystemEntities();
     Question question = context.Questions.Include("Answers")
         .FirstOrDefault(q => q.QuestionId == questionId);
     try
     {
         context.Answers.RemoveRange(question.Answers);
         context.Questions.Remove(question);
         context.SaveChanges();
         this.GridViewQuestions.PageIndex = 0;
         ErrorSuccessNotifier.AddInfoMessage("Question deleted.");
     }
     catch (Exception ex)
     {
         ErrorSuccessNotifier.AddErrorMessage(ex);
     }
 }
Exemplo n.º 18
0
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var dbContext  = new PollSystemEntities();
            int questionId = Convert.ToInt32(Request.Params["questionId"]);
            var question   = dbContext.Questions.Find(questionId);

            if (question != null)
            {
                this.LabelQuestionText.Text = Server.HtmlEncode(question.Text);

                this.RepeaterAnswers.DataSource = question.Answers.ToList();
                this.DataBind();
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("This question does not exist anymore");
            }
        }
Exemplo n.º 19
0
        protected void GridViewQuestions_SelectedIndexChanged(object sender, EventArgs e)
        {
            var dbContext  = new PollSystemEntities();
            int questionId =
                Convert.ToInt32(this.GridViewQuestions.SelectedDataKey.Value);

            var question = dbContext.Questions.Find(questionId);

            if (question != null)
            {
                this.RepeaterAnswers.DataSource = question.Answers.ToList();
                this.RepeaterAnswers.DataBind();
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("This question doesn't exist anymore");
            }
        }
Exemplo n.º 20
0
        protected void OnBtnCreateQuestion_Click(object sender, EventArgs e)
        {
            string questionText = this.TextBoxQuestionText.Text;

            if (questionText.Length < 4)
            {
                ErrorSuccessNotifier.AddErrorMessage("The question's length must be in range [4, 200] inclusive");

                if (answers.Count < 2)
                {
                    ErrorSuccessNotifier.AddErrorMessage("The question must have at least 2 answers");
                }
            }
            else if (answers.Count < 2)
            {
                ErrorSuccessNotifier.AddErrorMessage("The question must have at least 2 answers");
            }
            else
            {
                var question = new Question()
                {
                    Answers = answers.Select(answer => new Answer()
                    {
                        Text = answer
                    }).ToList(),
                    Text = questionText
                };

                try
                {
                    var dbContext = new PollSystemEntities();
                    dbContext.Questions.Add(question);
                    dbContext.SaveChanges();

                    this.TextBoxQuestionText.Text = "";
                    answers = new List <string>();
                    ErrorSuccessNotifier.AddSuccessMessage("Question created");
                }
                catch (Exception ex)
                {
                    ErrorSuccessNotifier.AddErrorMessage(ex);
                }
            }
        }
        // The id parameter name should match the DataKeyNames value set on the control
        public void GridViewQuestions_DeleteItem(int questionId)
        {
            var      context  = new PollSystemEntities();
            Question question = context.Questions.Include("Answers")
                                .FirstOrDefault(q => q.QuestionId == questionId);

            try
            {
                context.Answers.RemoveRange(question.Answers);
                context.Questions.Remove(question);
                context.SaveChanges();
                this.GridViewQuestions.PageIndex = 0;
                ErrorSuccessNotifier.AddInfoMessage("Question deleted.");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex);
            }
        }
Exemplo n.º 22
0
        protected void OnBtnVote_Command(object sender, CommandEventArgs e)
        {
            var dbContext = new PollSystemEntities();
            int answerId  = Convert.ToInt32(e.CommandArgument);

            var answer = dbContext.Answers.Find(answerId);

            if (answer != null)
            {
                answer.Votes++;
                dbContext.SaveChanges();

                ErrorSuccessNotifier.AddInfoMessage("You voted for " + answer.Text);
                Response.Redirect("~/VotingResults.aspx?questionId=" + answer.QuestionId);
            }
            else
            {
                ErrorSuccessNotifier.AddErrorMessage("This answer does not exist anymore");
            }
        }
Exemplo n.º 23
0
        public IQueryable <Question> GridViewQuestions_GetData()
        {
            var dbContext = new PollSystemEntities();

            return(dbContext.Questions.OrderBy(q => q.Text));
        }
 public IQueryable<Question> GridViewAllQuestions_GetData()
 {
     var context = new PollSystemEntities();
     var questions = context.Questions.OrderBy(q => q.Text);
     return questions;
 }