public void AddOptionToQuestion(int questionId, QuestionOption qOption) { Question question = QuestionManager.Find(questionId); if (question!=null && qOption!=null) { question.QuestionOption.Add(qOption); } }
// This is the Insert method to insert the entered QuestionOption item // USAGE: <asp:FormView InsertMethod="InsertItem"> public void InsertItem() { using (_db) { var item = new Authorization_App.Model.QuestionOption(); int questionId = (int) Session["questionId"]; QuestionService questionService = new QuestionService(_db); questionService.AddOptionToQuestion(questionId, item); TryUpdateModel(item); if (ModelState.IsValid) { // Save changes _db.QuestionOption.Add(item); _db.SaveChanges(); Response.Redirect("Default"); } } }