Advertisement
Guest User

Untitled

a guest
Jun 30th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. [HttpPost]
  2. [ValidateAntiForgeryToken]
  3. public ActionResult Create(FormCollection QuestionList)
  4. {
  5.  
  6. Survey survey = new Survey();
  7. foreach (var item in QuestionList.AllKeys)
  8. {
  9. if (item != "__RequestVerificationToken")
  10. {
  11. Question question = new Question();
  12. question.SurveyQuestion = QuestionList[item].ToString();
  13. question.Survey = survey;
  14. db.Questions.Add(question);
  15. }
  16.  
  17. }
  18. db.SaveChanges();
  19. return View();
  20. }
  21.  
  22. public class Survey
  23. {
  24. public int Id { get; set; }
  25. public virtual ICollection<Question> Questions { get; set; }
  26. public virtual ICollection<Answer> Answers { get; set; }
  27. }
  28.  
  29. public class Question
  30. {
  31. public int Id { get; set; }
  32. public string SurveyQuestion { get; set; }
  33. public int SurveyId { get; set; }
  34. public virtual ICollection<Answer> Answers { get; set; }
  35. public virtual Survey Survey { get; set; }
  36. }
  37.  
  38. public class Answer
  39. {
  40. public int Id { get; set; }
  41. public int Value { get; set; }
  42. public int QuestionId { get; set; }
  43. public int SurveyId { get; set; }
  44.  
  45. public virtual Question Question { get; set; }
  46. public virtual Survey Survey { get; set; }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement