コード例 #1
0
ファイル: forgot.aspx.cs プロジェクト: Lagomorphism/faviat
    protected void btn_Click(object sender, EventArgs e)
    {
        string id          = ((Control)sender).ID;
        int    question_id = 0;

        switch (id)
        {
        case "btn_check":
            int exist_indicator = BusinessLayer.Check_Username_Existence(txt_forgot_password.Text);

            if (exist_indicator == 0)
            {
                question_id          = LoadQuestions(txt_forgot_password.Text);
                pnl_email.Visible    = false;
                pnl_question.Visible = true;
                pnl_confirm.Visible  = false;
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<p class='error bold'>Your account does not exist. Please check email address again.</p>");
                lit_error.Text = sb.ToString();
            }
            break;

        case "btn_submit":
            tblQuestion       q = ModelLayer.GetQuestion(question_id);
            tblQuestionAnswer a = ModelLayer.GetQuestionAnswer(q.iQuestionAnswer);

            if (a.vQuestionAnswer == txt_question_answer.Text)
            {
                string result = SendEmail(txt_forgot_password.Text);

                if (result == "Success")
                {
                    pnl_email.Visible    = false;
                    pnl_question.Visible = false;
                    pnl_confirm.Visible  = true;
                }
                else
                {
                    Common.ErrorLog(@"c:\logs\debug.txt", result);
                }
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                sb.Append("<p class='error bold'>Your security question answer does not match with our records. Please check your answer again.</p>");
                lit_error.Text = sb.ToString();
            }
            break;

        case "btn_confirm":
            Response.RedirectToRoute("Login");
            break;

        default:
            break;
        }
    }
コード例 #2
0
 public void DeleteTest()
 {
     using (SurveyEntities dc = new SurveyEntities())
     {
         tblQuestionAnswer row = dc.tblQuestionAnswers.FirstOrDefault(qa => qa.IsCorrect == false);
         dc.tblQuestionAnswers.Remove(row);
         Assert.AreEqual(1, dc.SaveChanges());
     }
 }
コード例 #3
0
 public void InsertTest()
 {
     using (SurveyEntities dc = new SurveyEntities())
     {
         tblQuestionAnswer row = new tblQuestionAnswer
         {
             Id         = Guid.NewGuid(),
             AnswerId   = dc.tblAnswers.FirstOrDefault(a => a.Answer == "WitchSand").Id,
             QuestionId = dc.tblQuestions.FirstOrDefault(q => q.Question == "What color is #5254FF").Id,
             IsCorrect  = false
         };
         dc.tblQuestionAnswers.Add(row);
         Assert.AreEqual(1, dc.SaveChanges());
     }
 }
コード例 #4
0
ファイル: Question.cs プロジェクト: B-Lemke/FVTC_SurveyMaker
        public int SaveAnswers()
        {
            //Delete all current questionanswers in the database for this question and save the current ones

            try
            {
                using (SurveyEntities dc = new SurveyEntities())
                {
                    //If the Id is set, get the result in the table where it matches
                    if (this.Id != Guid.Empty)
                    {
                        //get all of the questionanswers with this questionId
                        var questionAnswers = dc.tblQuestionAnswers.Where(qa => qa.QuestionId == this.Id);

                        //Delete the questionanswers with this questionId from the database
                        foreach (tblQuestionAnswer qa in questionAnswers)
                        {
                            dc.tblQuestionAnswers.Remove(qa);
                        }

                        //Foreach question answer on the AnswerList, put it in QuestionAnswers with this question ID
                        foreach (Answer a in Answers)
                        {
                            //set properties
                            tblQuestionAnswer questionAnswer = new tblQuestionAnswer();
                            questionAnswer.AnswerId   = a.Id;
                            questionAnswer.QuestionId = this.Id;
                            questionAnswer.IsCorrect  = a.IsCorrect;
                            questionAnswer.Id         = Guid.NewGuid();

                            //add to the tblQuestionAnswers
                            dc.tblQuestionAnswers.Add(questionAnswer);
                        }

                        //Return the number of rows affected
                        return(dc.SaveChanges());
                    }
                    else
                    {
                        throw new Exception("Id not set on Question");
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #5
0
        public void UpdateTest()
        {
            using (SurveyEntities dc = new SurveyEntities())
            {
                tblQuestionAnswer row = dc.tblQuestionAnswers.FirstOrDefault(qa => qa.IsCorrect == false);
                if (row != null)
                {
                    row.IsCorrect = true;
                }
                Assert.AreEqual(1, dc.SaveChanges());

                //change iscorrect back to false so it can be deleted properly
                row.IsCorrect = false;
                dc.SaveChanges();
            }
        }
コード例 #6
0
 public static int Delete(Guid questionId, Guid answerId)
 {
     try
     {
         using (SurveyEntities dc = new SurveyEntities())
         {
             tblQuestionAnswer row = dc.tblQuestionAnswers.FirstOrDefault(qa => qa.QuestionId == questionId && qa.AnswerId == answerId);
             dc.tblQuestionAnswers.Remove(row);
             return(dc.SaveChanges());
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
コード例 #7
0
        public void DeleteTest()
        {
            using (SurveyEntities dc = new SurveyEntities())
            {
                //get a question and answer
                tblAnswer   answer   = dc.tblAnswers.FirstOrDefault(a => a.Text == "Kelly Kapoor");
                tblQuestion question = dc.tblQuestions.FirstOrDefault(q => q.Text == "Who sprouts mung beans in their desk drawers?");

                tblQuestionAnswer questionAnswer = dc.tblQuestionAnswers.FirstOrDefault(q => (q.AnswerId == answer.Id) && (q.QuestionId == question.Id));

                dc.tblQuestionAnswers.Remove(questionAnswer);

                int results = dc.SaveChanges();

                Assert.IsTrue(results > 0);
            }
        }
コード例 #8
0
        public void InsertTest()
        {
            using (SurveyEntities dc = new SurveyEntities())
            {
                //get a question and answer
                tblAnswer   answer   = dc.tblAnswers.FirstOrDefault(a => a.Text == "Kelly Kapoor");
                tblQuestion question = dc.tblQuestions.FirstOrDefault(q => q.Text == "Who sprouts mung beans in their desk drawers?");

                //set properties
                tblQuestionAnswer questionAnswer = new tblQuestionAnswer();
                questionAnswer.Id         = Guid.NewGuid();
                questionAnswer.QuestionId = question.Id;
                questionAnswer.AnswerId   = answer.Id;
                questionAnswer.IsCorrect  = false;

                dc.tblQuestionAnswers.Add(questionAnswer);

                int results = dc.SaveChanges();

                Assert.IsTrue(results > 0);
            }
        }
コード例 #9
0
    public static tblQuestionAnswer GetQuestionAnswer(int iQuestionAnswer)
    {
        tblQuestionAnswer a = new tblQuestionAnswer();

        return(a);
    }