public async Task <IActionResult> Create([Bind("CategoryId,Question,PointValue,Id")] Questions questions) { if (ModelState.IsValid) { _context.Add(questions); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", questions.CategoryId); ViewData["CategoryName"] = new SelectList(_context.Categories, "Id", "Name", questions.CategoryId); return(View(questions)); }
public async Task <IActionResult> Create([Bind("QuestionId,Answer,CorrectAnswer,Id")] Answers answers) { if (ModelState.IsValid) { _context.Add(answers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } //ViewData["QuestionId"] = new SelectList(_context.Questions, "Id", "Id", answers.QuestionId); ViewData["QuestionName"] = new SelectList(_context.Questions, "Id", "Question", answers.QuestionId); return(View(answers)); }
public async Task <IActionResult> Create([Bind("Name,Id,Active")] Categories categories) { if (ModelState.IsValid) { _context.Add(categories); await _context.SaveChangesAsync(); var questions = new List <Questions> { new Questions { Question = "Edit and Enter Question 1", PointValue = 100, Categories = categories }, new Questions { Question = "Edit and Enter Question 2", PointValue = 200, Categories = categories }, new Questions { Question = "Edit and Enter Question 3", PointValue = 300, Categories = categories }, new Questions { Question = "Edit and Enter Question 4", PointValue = 400, Categories = categories }, new Questions { Question = "Edit and Enter Question 5", PointValue = 500, Categories = categories } }; _context.Questions.AddRange(questions); await _context.SaveChangesAsync(); var answers = new List <Answers> { new Answers { Answer = "Edit and Enter Answer a", Question = questions[0], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer b", Question = questions[0], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer c", Question = questions[0], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer d", Question = questions[0], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer a", Question = questions[1], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer b", Question = questions[1], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer c", Question = questions[1], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer d", Question = questions[1], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer a", Question = questions[2], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer b", Question = questions[2], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer c", Question = questions[2], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer d", Question = questions[2], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer a", Question = questions[3], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer b", Question = questions[3], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer c", Question = questions[3], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer d", Question = questions[3], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer a", Question = questions[4], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer b", Question = questions[4], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer c", Question = questions[4], CorrectAnswer = false }, new Answers { Answer = "Edit and Enter Answer d", Question = questions[4], CorrectAnswer = false } }; _context.Answers.AddRange(answers); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(categories)); }