public void Test_CreateMultipleChoiseQuestion_Empty_answer() { newQuestion = newQuestion_copy; newQuestion.Answers = new List <string>() { "a", "b", "" }; handler.CreateMultipleChoiseQuestion(newQuestion, GameID); }
public void Test_UpdateMultipleChoiseQuestion_Empty_answer() { existingQuestion = existingQuestion_copy; existingQuestion.Answers = new List <string>() { "a", "b", "" }; handler.UpdateMultipleChoiseQuestion(existingQuestion); }
public void UpdateMultipleChoiseQuestion(MultipleChoiseQuestion Question) { if (_dbContext.MultipleChoiseQuestion.Where(q => q.ID == Question.ID).Count() == 0) { throw new Exception("Er is geen vraag gevonden met het ID : `" + Question.ID.ToString() + "`"); } if (Question.Question.Length < 5 || Question.Question.Length > 50) { throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!"); } if (Question.Question.Split(' ').Count() < 3) { throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!"); } if (Question.Correctanswer == "") { throw new Exception("Er moet een antwoord gegeven worden!"); } if (Question.Answers.Count < 3) { throw new Exception("Je moet minimaal 3 antwoorden geven!"); } if (Question.Answers.Contains("")) { throw new Exception("Je mag geen leeg antwoord geven!"); } Question.Answers.Add(Question.Correctanswer); _dbContext.MultipleChoiseQuestionAnswer.RemoveRange(_dbContext.MultipleChoiseQuestionAnswer.Where(q => q.MultipleChoiseQuestionID == Question.ID)); foreach (string Answer in Question.Answers) { _dbContext.MultipleChoiseQuestionAnswer.Add(new Models.DataModels.MultipleChoiseQuestionAnswer() { MultipleChoiseQuestionID = Question.ID, Answer = Answer }); } _dbContext.SaveChanges(); var id = _dbContext.MultipleChoiseQuestionAnswer.Where(q => q.Answer == Question.Correctanswer && q.MultipleChoiseQuestionID == Question.ID).Select(q => q.ID).First(); int CorrectAnswerID = Convert.ToInt32(id); Models.DataModels.MultipleChoiseQuestion MultipleChoiseQuestion = _dbContext.MultipleChoiseQuestion.Where(q => q.ID == Question.ID).First(); MultipleChoiseQuestion.Question = Question.Question; MultipleChoiseQuestion.CorrectAnswerID = CorrectAnswerID; _dbContext.SaveChanges(); }
public void UpdateMultipleChoiseQuestion(MultipleChoiseQuestion question) { if (dbContext.MultipleChoiseQuestion.Where(q => q.ID == question.ID).Count() == 0) { throw new Exception("Er is geen vraag gevonden met het ID : `" + question.ID.ToString() + "`"); } if (question.Question.Length < 5 || question.Question.Length > 50) { throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!"); } if (question.Question.Split(' ').Count() < 3) { throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!"); } if (question.Correctanswer == "") { throw new Exception("Er moet een antwoord gegeven worden!"); } if (question.answer.Count < 3) { throw new Exception("Je moet minimaal 3 antwoorden geven!"); } if (question.answer.Contains("")) { throw new Exception("Je mag geen leeg antwoord geven!"); } dbContext.MultipleChoiseQuestionAnswer.RemoveRange(dbContext.MultipleChoiseQuestionAnswer.Where(q => q.MultipleChoiseQuestionID == question.ID)); dbContext.MultipleChoiseQuestionAnswer.Add(new Models.DataModels.MultipleChoiseQuestionAnswer() { MultipleChoiseQuestionID = question.ID, Answer = question.Correctanswer }); //SQL.Insert("INSERT INTO `mcanswer` (`ID`, `mcQuestionID`, `answer`) VALUES (NULL, '" + QuestionID + "', '" + question.Correctanswer + "')"); foreach (string answer in question.answer) { dbContext.MultipleChoiseQuestionAnswer.Add(new Models.DataModels.MultipleChoiseQuestionAnswer() { MultipleChoiseQuestionID = question.ID, Answer = answer }); //SQL.Insert("INSERT INTO `mcanswer` (`ID`, `mcQuestionID`, `answer`) VALUES (NULL, '" + QuestionID + "', '" + answer + "')"); } int CorrectAnswerID = Convert.ToInt32(dbContext.MultipleChoiseQuestionAnswer.Where(q => q.Answer == question.Correctanswer && q.MultipleChoiseQuestionID == question.ID).Select(q => q.ID)); Models.DataModels.MultipleChoiseQuestion mcQ = dbContext.MultipleChoiseQuestion.Where(q => q.ID == question.ID).First(); mcQ.Question = question.Question; mcQ.CorrectAnswerID = CorrectAnswerID; dbContext.SaveChanges(); }
public MultipleChoiseQuestion GetMultipleChoiseQuestion(int ID) { if (dbContext.MultipleChoiseQuestion.Where(q => q.ID == ID).Count() == 0) { throw new Exception("Er is geen vraag gevonden met het ID : `" + ID.ToString() + "`"); } MultipleChoiseQuestion multipleChoiseQuestion = new MultipleChoiseQuestion(); Models.DataModels.MultipleChoiseQuestion Q = dbContext.MultipleChoiseQuestion.Where(q => q.ID == ID).First(); multipleChoiseQuestion.ID = ID; multipleChoiseQuestion.Question = Q.Question; multipleChoiseQuestion.answer = dbContext.MultipleChoiseQuestionAnswer.Where(qa => qa.MultipleChoiseQuestionID == Q.ID).Select(qa => qa.Answer).ToList(); multipleChoiseQuestion.Correctanswer = dbContext.MultipleChoiseQuestionAnswer.Where(qa => qa.ID == Q.CorrectAnswerID).Select(qa => qa.Answer).First(); return(multipleChoiseQuestion); }
public void Test_CreateMultipleChoiseQuestion_Question_char_3() { newQuestion = newQuestion_copy; newQuestion.Question = "333"; handler.CreateMultipleChoiseQuestion(newQuestion, GameID); }
public void Test_CreateMultipleChoiseQuestion_WrongGameID() { newQuestion = newQuestion_copy; handler.CreateMultipleChoiseQuestion(newQuestion, 999); }
public void Test_UpdateMultipleChoiseQuestion_No_answer() { existingQuestion = existingQuestion_copy; existingQuestion.Correctanswer = ""; handler.UpdateMultipleChoiseQuestion(existingQuestion); }
public void Test_UpdateMultipleChoiseQuestion_Question_2_words() { existingQuestion = existingQuestion_copy; existingQuestion.Question = "addwwds dssaswdasdazdawwdadw"; handler.UpdateMultipleChoiseQuestion(existingQuestion); }
public void Test_UpdateMultipleChoiseQuestion_Question_char_55() { existingQuestion = existingQuestion_copy; existingQuestion.Question = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; handler.UpdateMultipleChoiseQuestion(existingQuestion); }
public void Test_UpdateMultipleChoiseQuestion_WrongGameID() { existingQuestion = existingQuestion_copy; existingQuestion.ID = 999; handler.UpdateMultipleChoiseQuestion(existingQuestion); }
public void Test_CreateMultipleChoiseQuestion_No_answer() { newQuestion = newQuestion_copy; newQuestion.Correctanswer = ""; handler.CreateMultipleChoiseQuestion(newQuestion, GameID); }
public void Test_CreateMultipleChoiseQuestion_Question_2_words() { newQuestion = newQuestion_copy; newQuestion.Question = "addwwds dssaswdasdazdawwdadw"; handler.CreateMultipleChoiseQuestion(newQuestion, GameID); }
public void CreateMultipleChoiseQuestion(MultipleChoiseQuestion question, int GameID) { if (dbContext.Game.Where(g => g.ID == GameID).Count() == 0) { throw new Exception("Er is geen game gevonden met het ID : `" + GameID.ToString() + "`"); } if (question.Question.Length < 5 || question.Question.Length > 50) { throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!"); } if (question.Question.Split(' ').Count() < 3) { throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!"); } if (question.Correctanswer == "") { throw new Exception("Er moet een antwoord gegeven worden!"); } if (question.answer.Count < 3) { throw new Exception("Je moet minimaal 3 antwoorden geven!"); } if (question.answer.Contains("")) { throw new Exception("Je mag geen leeg antwoord geven!"); } //string qry = "INSERT INTO `mcquestion` (`ID`, `Question`, `CorrectanswerID`) VALUES (NULL, '"+question.Question+"', '"+"0"+"')"; dbContext.MultipleChoiseQuestion.Add(new Models.DataModels.MultipleChoiseQuestion() { Question = question.Question, CorrectAnswerID = 0 }); dbContext.SaveChanges(); int QuestionID = dbContext.MultipleChoiseQuestion.OrderByDescending(o => o.ID).FirstOrDefault().ID; dbContext.MultipleChoiseQuestionAnswer.Add(new Models.DataModels.MultipleChoiseQuestionAnswer() { MultipleChoiseQuestionID = QuestionID, Answer = question.Correctanswer }); //SQL.Insert("INSERT INTO `mcanswer` (`ID`, `mcQuestionID`, `answer`) VALUES (NULL, '" + QuestionID + "', '" + question.Correctanswer + "')"); foreach (string answer in question.answer) { dbContext.MultipleChoiseQuestionAnswer.Add(new Models.DataModels.MultipleChoiseQuestionAnswer() { MultipleChoiseQuestionID = QuestionID, Answer = answer }); //SQL.Insert("INSERT INTO `mcanswer` (`ID`, `mcQuestionID`, `answer`) VALUES (NULL, '" + QuestionID + "', '" + answer + "')"); } dbContext.SaveChanges(); int CorrectanswerID = dbContext.MultipleChoiseQuestionAnswer.Where(a => a.MultipleChoiseQuestionID == QuestionID && a.Answer == question.Correctanswer).OrderByDescending(o => o.ID).FirstOrDefault().ID; Models.DataModels.MultipleChoiseQuestion mcq = dbContext.MultipleChoiseQuestion.Where(q => q.ID == QuestionID).OrderByDescending(o => o.ID).FirstOrDefault(); mcq.CorrectAnswerID = CorrectanswerID; dbContext.SaveChanges(); //SQL.Update("UPDATE `mcquestion` SET `CorrectanswerID` = '"+CorrectanswerID+"' WHERE `mcquestion`.`ID` = '"+QuestionID+"'"); dbContext.ChartGroup.Add(new Models.DataModels.ChartGroup()); dbContext.SaveChanges(); int chartGroupID = dbContext.ChartGroup.OrderByDescending(o => o.ID).FirstOrDefault().ID; dbContext.Question.Add(new Models.DataModels.Question() { GameID = GameID, QuestionType = Models.DataModels.QuestionType.MultipleChoise, ChartGroupID = chartGroupID, QuestionTypeID = QuestionID }); dbContext.SaveChanges(); //SQL.Insert("INSERT INTO `chartgroup`(`ID`) VALUES(NULL); INSERT INTO `question` (`ID`, `gameID`, `Type`, `QuestionTypeID`, `ChartGroupID`) VALUES (NULL, '" + GameID.ToString() + "', '1', '" + QuestionID + "', ( SELECT MAX(`chartgroup`.`ID`) FROM `chartgroup`))"); }
public void CreateMultipleChoiseQuestion(MultipleChoiseQuestion Question, int GameID) { if (_dbContext.Game.Where(g => g.ID == GameID).Count() == 0) { throw new Exception("Er is geen game gevonden met het ID : `" + GameID.ToString() + "`"); } if (Question.Question.Length < 5 || Question.Question.Length > 50) { throw new Exception("Een vraag moet tussen de 5 en 50 characters bevatten!"); } if (Question.Question.Split(' ').Count() < 3) { throw new Exception("Een vraag moet uit meer dan 3 woorden bestaan!"); } if (Question.Correctanswer == "") { throw new Exception("Er moet een antwoord gegeven worden!"); } if (Question.Answers.Count == 0) { throw new Exception("Je moet minimaal 2 antwoorden geven!"); } if (Question.Answers.Contains("")) { throw new Exception("Je mag geen leeg antwoord geven!"); } _dbContext.MultipleChoiseQuestion.Add(new Models.DataModels.MultipleChoiseQuestion() { Question = Question.Question, CorrectAnswerID = 0 }); _dbContext.SaveChanges(); int QuestionID = _dbContext.MultipleChoiseQuestion.OrderByDescending(o => o.ID).FirstOrDefault().ID; _dbContext.MultipleChoiseQuestionAnswer.Add(new Models.DataModels.MultipleChoiseQuestionAnswer() { MultipleChoiseQuestionID = QuestionID, Answer = Question.Correctanswer }); foreach (string Answer in Question.Answers) { _dbContext.MultipleChoiseQuestionAnswer.Add(new Models.DataModels.MultipleChoiseQuestionAnswer() { MultipleChoiseQuestionID = QuestionID, Answer = Answer }); } _dbContext.SaveChanges(); int CorrectanswerID = _dbContext.MultipleChoiseQuestionAnswer.Where(a => a.MultipleChoiseQuestionID == QuestionID && a.Answer == Question.Correctanswer).OrderByDescending(o => o.ID).FirstOrDefault().ID; Models.DataModels.MultipleChoiseQuestion MultipleChoiseQuestion = _dbContext.MultipleChoiseQuestion.Where(q => q.ID == QuestionID).OrderByDescending(o => o.ID).FirstOrDefault(); MultipleChoiseQuestion.CorrectAnswerID = CorrectanswerID; _dbContext.SaveChanges(); _dbContext.ChartGroup.Add(new Models.DataModels.ChartGroup()); _dbContext.SaveChanges(); int ChartGroupID = _dbContext.ChartGroup.OrderByDescending(o => o.ID).FirstOrDefault().ID; _dbContext.Question.Add(new Models.DataModels.Question() { GameID = GameID, QuestionType = Models.DataModels.QuestionType.MultipleChoise, ChartGroupID = ChartGroupID, QuestionTypeID = QuestionID }); _dbContext.SaveChanges(); }