using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace WebApplication1.Controllers {
	public class ExempleChampCacheController : Controller {
	  static string[] Questions = { "Un sport de combat", "Un produit de 1ère nécessité", "Un sport d'équipe", "Une religion monothéiste", "La seule faiblesse de Chuck Norris" };
	  public ActionResult Index() {
	    ViewBag.Precedent = DateTime.Now.ToString( "G" );
			int[] reponses = Request.Form["r"]?.Split( ',' ).Select( str => int.Parse( str ) ).ToArray();
			reponses = reponses ?? new int[0];
			ViewBag.Questions = ExempleChampCacheController.Questions;
			ViewBag.Selectionner = reponses;
	    if( Request.Form.Count > 0 ) { // post
	      string r = Request.Form["r"];
	      DateTime precedent = DateTime.Parse( Request.Form["precedent"] );
	      var delai = (DateTime.Now - precedent).TotalSeconds;
	      var ok = reponses.Length == Questions.Length ? "correctement" : "de travers";
	      ViewBag.Message = $"Il vous a fallu {delai:0.00} seconde(s) pour répondre {ok} !\nVous pouvez rejouer.";
	    }
      else {
	      ViewBag.Message = $"Répondez vite, répondez bien !";
	    }
	    return View();
	  }
	}
}