//Add Question to database public string addQuestion(string questionName, int quizID, List <string> answers) { try { CommonLayer.question quest = new CommonLayer.question(); quest.question1 = questionName; quest.quizID = quizID; this.Entity.questions.AddObject(quest); this.Entity.SaveChanges(); int id = -1; //searxh in list of answers foreach (string name in answers) { CommonLayer.answer a = new CommonLayer.answer(); a.answer1 = name; a.questionID = quest.questionID; this.Entity.answers.AddObject(a); this.Entity.SaveChanges(); id = a.answerID; } // Add questions. CommonLayer.question uquest = getQuestionById(quest.questionID); uquest.correctAnswerID = id; this.Entity.SaveChanges(); return("Success"); } catch (Exception ex) { return(ex.Message); } }
//Add Question to database public string addQuestion(string questionName, int quizID, List<string> answers) { try { CommonLayer.question quest = new CommonLayer.question(); quest.question1 = questionName; quest.quizID = quizID; this.Entity.questions.AddObject(quest); this.Entity.SaveChanges(); int id = -1; //searxh in list of answers foreach (string name in answers) { CommonLayer.answer a = new CommonLayer.answer(); a.answer1 = name; a.questionID = quest.questionID; this.Entity.answers.AddObject(a); this.Entity.SaveChanges(); id= a.answerID; } // Add questions. CommonLayer.question uquest = getQuestionById(quest.questionID); uquest.correctAnswerID = id; this.Entity.SaveChanges(); return "Success"; } catch (Exception ex) { return ex.Message; } }
/// <summary> /// Create a new question object. /// </summary> /// <param name="questionID">Initial value of the questionID property.</param> /// <param name="question1">Initial value of the question1 property.</param> /// <param name="quizID">Initial value of the quizID property.</param> public static question Createquestion(global::System.Int32 questionID, global::System.String question1, global::System.Int32 quizID) { question question = new question(); question.questionID = questionID; question.question1 = question1; question.quizID = quizID; return question; }
/// <summary> /// Deprecated Method for adding a new object to the questions EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToquestions(question question) { base.AddObject("questions", question); }