Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult Create(FormCollection QuestionList)
- {
- Survey survey = new Survey();
- foreach (var item in QuestionList.AllKeys)
- {
- if (item != "__RequestVerificationToken")
- {
- Question question = new Question();
- question.SurveyQuestion = QuestionList[item].ToString();
- question.Survey = survey;
- db.Questions.Add(question);
- }
- }
- db.SaveChanges();
- return View();
- }
- public class Survey
- {
- public int Id { get; set; }
- public virtual ICollection<Question> Questions { get; set; }
- public virtual ICollection<Answer> Answers { get; set; }
- }
- public class Question
- {
- public int Id { get; set; }
- public string SurveyQuestion { get; set; }
- public int SurveyId { get; set; }
- public virtual ICollection<Answer> Answers { get; set; }
- public virtual Survey Survey { get; set; }
- }
- public class Answer
- {
- public int Id { get; set; }
- public int Value { get; set; }
- public int QuestionId { get; set; }
- public int SurveyId { get; set; }
- public virtual Question Question { get; set; }
- public virtual Survey Survey { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement