Esempio n. 1
0
        public async Task <JsonResult> GetTextFromUrlAsync(string urlToSearch)
        {
            var wordCounts = await _textSplitterService.GetWordsFromUrlAsync(urlToSearch, 100);

            _wordCounterService.StoreWordCounts(wordCounts, 100);

            return(new JsonResult(wordCounts));
        }
        public async Task <IActionResult> Index(string urlToSearch)
        {
            try
            {
                var wordCounts = await _textSplitterService.GetWordsFromUrlAsync(urlToSearch, 100);

                _wordCounterService.StoreWordCounts(wordCounts, 100);

                var viewModel = new WordCounterViewModel
                {
                    Url              = urlToSearch,
                    CountedWords     = wordCounts,
                    CountedWordsJson = Json(wordCounts)
                };
                return(View(viewModel));
            }
            catch (Exception e)
            {
                ViewData["ErrorMessage"] = e.Message;
                ViewData["ErrorStack"]   = e.StackTrace;
                ViewData["ErrorInner"]   = e.InnerException?.Message;
                return(View("Error"));
            }
        }