public ActionResult Index(GuessingViewModel m)
        {
            int?test = HttpContext.Session.GetInt32("Attempts");

            test++;
            HttpContext.Session.SetInt32("Attempts", (int)test);
            m.CheckTheGuess(m.Guessed, HttpContext.Session.GetInt32("Test Int"), HttpContext.Session.GetInt32("Attempts"));
            return(View(m));
        }
        //GET - Create a random number every time we refresh the page
        public ActionResult Index()
        {
            //Generate the number ans store it in a session
            Random rnd    = new Random();
            int    number = rnd.Next(1, 101);

            HttpContext.Session.SetInt32("Test Int", number);
            HttpContext.Session.SetInt32("Attempts", 0);

            GuessingViewModel m = new GuessingViewModel();

            return(View(m));
        }
        public async Task <ActionResult> Index()
        {
            var randomizer = new Random();
            var guessRow   = _guessingSet.ElementAt(randomizer.Next(0, _guessingSet.Count - 1)).Value;

            var sourceLanguage = await _context.Languages.SingleOrDefaultAsync(l => l.Id == _sourceLanguageGuid);

            var guessingVm = new GuessingViewModel
            {
                AllRowTranslations = await _service.GetTranslations(sourceLanguage?.Code, guessRow.GetTranslationByLanguageCode(sourceLanguage?.Code)),
                MarkedCorrect      = false,
                SourceText         = guessRow.GetTranslationByLanguageCode(sourceLanguage?.Code),
                TranslatedText     = null,
                TranslationRowGuid = guessRow.Id
            };

            return(View(guessingVm));
        }
        public async Task <ActionResult> SubmitGuess(string checkButton, string forceButton, GuessingViewModel indexVm)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index", indexVm));
            }

            if (checkButton != null)
            {
                indexVm.MarkedCorrect = false;
            }
            else
            {
                indexVm.MarkedCorrect = true;
            }

            var sourceLanguage = await _context.Languages.SingleOrDefaultAsync(l => l.Id == _sourceLanguageGuid);

            var targetLanguage = await _context.Languages.SingleOrDefaultAsync(l => l.Id == _targetLanguageGuid);

            foreach (var translation in indexVm.AllRowTranslations)
            {
                var correctTranslation = translation.GetTranslationByLanguageCode(targetLanguage.Code);
                indexVm.CorrectlyTranslatedText = correctTranslation;

                if (indexVm.TranslatedText == correctTranslation)
                {
                    var successfulGuess = new GuessAttempt();
                    _context.GuessAttempts.Add(successfulGuess.GetGuessAttempt(indexVm.SourceText,
                                                                               indexVm.TranslatedText,
                                                                               sourceLanguage,
                                                                               targetLanguage,
                                                                               translation.Id,
                                                                               true,
                                                                               indexVm.MarkedCorrect));

                    await _context.SaveChangesAsync();

                    return(RedirectToAction("Index"));
                }
                else
                {
                    var failedGuess = new GuessAttempt();
                    _context.GuessAttempts.Add(failedGuess.GetGuessAttempt(indexVm.SourceText,
                                                                           indexVm.TranslatedText,
                                                                           sourceLanguage,
                                                                           targetLanguage,
                                                                           indexVm.TranslationRowGuid,
                                                                           false,
                                                                           indexVm.MarkedCorrect));

                    await _context.SaveChangesAsync();
                }
            }
            indexVm.TranslatedText = null;
            indexVm.MarkedCorrect  = false;
            return(View("Index", indexVm));
        }