using FinalProject.Models;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
namespace FinalProject.Controllers
{
public class GameController : Controller
{
private FinalProjectContext _context;
public GameController(FinalProjectContext context)
{
_context = context;
}
public IActionResult Index()
{
List<Question> questions = _context.Questions.ToList();
GameViewModel gameViewModel = new GameViewModel();
gameViewModel.Questions = questions;
return View(gameViewModel);
}
[HttpPost]
public IActionResult Save(GameViewModel gameViewModel)
{
if (ModelState.IsValid)
{
foreach (Question question in gameViewModel.Questions)
{
//if (question.Genus != gameViewModel.UserInput)
// ModelState.AddModelError("", question.Species + " is wrong!");
string test = "Genus is " + question.Genus + " input is " + gameViewModel.UserInput;
}
return RedirectToAction("Index", "Home");
}
else
{
return View(gameViewModel);
}
}
}
}