Exemple #1
0
        public PlayVM NewGame(HttpContext context, InputLangOption langOption)
        {
            var playVM = NextPlayVM(langOption);

            _session.SaveTutorContext(context, langOption, playVM);

            return(playVM);
        }
Exemple #2
0
        public void SaveTutorContext(HttpContext context, InputLangOption langOption, PlayVM playVM)
        {
            var      sessionKey = context.User.Identity.Name + sessionKeyEnd;
            ISession session    = context.Session;

            var tutorSession = new TutorSessionModel
            {
                LangOption  = langOption,
                Word        = playVM.Word,
                Translation = playVM.Translation,
            };

            session.SetString(sessionKey, JsonConvert.SerializeObject(tutorSession));
        }
Exemple #3
0
        private PlayVM NextPlayVM(InputLangOption langOption)
        {
            var russVocab = langOption.IdTopic == 0
                ? _postgres.Word.ToList()
                : _postgres.Word.Where(w => w.IdTopic == langOption.IdTopic).ToList();

            var rndNum  = rnd.Next(russVocab.Count);
            var rusWord = russVocab[rndNum].NameWord;

            var nativWord = langOption.LngFrom == Languages.ru
                ? rusWord
                : _translator.TranslateAsync(rusWord, Languages.ru, langOption.LngFrom).Result;

            var translation = _translator.TranslateAsync(nativWord, langOption).Result;

            return(new PlayVM
            {
                Word = nativWord,
                WordHelp = GetWordHelp(translation),
                Translation = translation,
            });
        }
 public async Task <string> TranslateAsync(string text, InputLangOption langOption)
 {
     return(await wrapper.TranslateText(text, $"{langOption.LngFrom.ToString()}-{langOption.LngTo.ToString()}"));
 }
        public IActionResult Start(InputLangOption langOption)
        {
            var playModel = _tutorService.NewGame(this.HttpContext, langOption);

            return(View(playModel));
        }