protected void Save_Command(object sender, CommandEventArgs e)
        {
            var context = new ConquistadorEntities();
            int questionId = Convert.ToInt32(Request.Params["id"]);

            if (questionId == 0)
            {
                isNewQuestion = true;
            }
            if (!isNewQuestion)
            {
                question = context.Questions.Find(questionId);
            }
            else
            {
                question = new Question();
                context.Questions.Add(question);
            }

            question.TextContent = this.TextBoxEdit.Text;
            question.IsApproved = this.CheckBoxApproved.Checked;
            try
            {
                context.SaveChanges();
                Response.Redirect("EditQuestions.aspx", false);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex.Message);
                return;
            }
        }
        protected void EditAnswer_Command(object sender, CommandEventArgs e)
        {
            var context = new ConquistadorEntities();

            question = context.Questions.Find(questionId);

            if (answerId == 0)
            {
                isNewAnswer = true;
                answer = new Answer();
                answer.QuestionId = question.Id;
                context.Answers.Add(answer);
            }

            if (!isNewAnswer)
            {
                answer = context.Answers.Find(answerId);
            }

            try
            {
                answer.ContentText = this.TextBoxEdit.Text;
                context.SaveChanges();
                Response.Redirect("EditQuestions.aspx", false);
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex.Message);
                return;
            }
        }
        protected void ButtonSubmit_Click(object sender, EventArgs e)
        {
            string questionText = this.TextBoxQuestion.Text;
            //validate q
            if (string.IsNullOrEmpty(questionText))
            {
                ErrorSuccessNotifier.AddErrorMessage("The question field cannot be empty!");
                return;
            }

            List<Answer> answers = new List<Answer>();
            answers.Add(new Answer() { ContentText = this.TextBoxAnswer1.Text });
            answers.Add(new Answer() { ContentText = this.TextBoxAnswer2.Text });
            answers.Add(new Answer() { ContentText = this.TextBoxAnswer3.Text });
            answers.Add(new Answer() { ContentText = this.TextBoxAnswer4.Text });
            //validate answers

            int correctAnswerIndex = int.Parse(this.DropDownCorrectAnswer.SelectedValue) - 1;
            for (int i = 0; i < answers.Count; i++)
            {
                if (string.IsNullOrEmpty(answers[i].ContentText))
                {
                    ErrorSuccessNotifier.AddErrorMessage("An answer field cannot be empty.");
                    return;
                }
                if (i == correctAnswerIndex)
                {
                    answers[i].IsCorrect = true;
                    break;
                }
            }

            ConquistadorEntities context = new ConquistadorEntities();

            try
            {
                Question created = new Question() { TextContent = questionText, Answers = answers, IsApproved = true };
                context.Questions.Add(created);
                context.SaveChanges();
                ErrorSuccessNotifier.AddSuccessMessage("Question was added.");
            }
            catch (Exception ex)
            {
                ErrorSuccessNotifier.AddErrorMessage(ex.Message);
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            var context = new ConquistadorEntities();

            if (questionId == 0)
            {
                isNewQuestion = true;
            }

            if (!isNewQuestion)
            {
                question = context.Questions.Find(questionId);
                this.TextBoxEdit.Text = question.TextContent;
                this.CheckBoxApproved.Checked = question.IsApproved == true? true : false;
                this.RepeaterAnswers.DataSource = question.Answers.ToList();
                this.DataBind();
            }

            else
            {
                this.TextBoxEdit.Text = "";
            }
        }