예제 #1
0
        public async Task <IActionResult> CheckFromFile(IFormFile file, TextToCheck textToCheck, Frequencies freq)
        {
            if (file == null || file.Length == 0)
            {
                return(View("Error", "Nie wybrano pliku"));
            }
            var path = Path.Combine(
                Directory.GetCurrentDirectory(), "wwwroot",
                file.FileName);

            using (var stream = new FileStream(path, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            string text = await file.ReadAsStringAsync();

            string extension = Path.GetExtension(path);

            if (extension != ".txt")
            {
                return(View("Error", "Wprowadzono niepoprawny format pliku! Aplikacja obsługuje pliki .txt."));
            }

            textToCheck.Text       = text.ToLower();
            textToCheck.TextLength = textToCheck.Text.Length;

            // Counting instances of letters in the text
            textToCheck = textToCheck.MakeFrequency(textToCheck);

            textToCheck = freq.ComparingLanguage(textToCheck, freq);

            return(View("Score", textToCheck));
        }
예제 #2
0
        public ViewResult Index(TextToCheck textToCheck, FrequencyOfLetters frequencyOfLetters, Frequencies freq)
        {
            if (string.IsNullOrEmpty(textToCheck.Text))
            {
                return(View("Error", "Należy podać tekst do przetłumaczenia!"));
            }

            textToCheck.TextLength = textToCheck.Text.Length;
            textToCheck.Text       = textToCheck.Text.ToLower();

            // Counting instances of letters in the text
            textToCheck = textToCheck.MakeFrequency(textToCheck);

            textToCheck = freq.ComparingLanguage(textToCheck, freq);

            return(View("Score", textToCheck));
        }