public IActionResult Index(IFormFile file, string word) { using (var reader = new StreamReader(file.OpenReadStream())) { var fileContent = reader.ReadToEnd(); var sentences = fileContent.Split('.'); foreach (var s in sentences) { if (s.Contains(word)) { var count = s.Split(' ').Count(x => x == word); Sentence sentanceToAdd = new Sentence { Count = count, SentenceInRevert = RevertHelper.Revert(s), Word = word }; _context.Add(sentanceToAdd); } } _context.SaveChanges(); ViewBag.Sentences = GetSavedSentences(); return(View()); } }
private List <string> GetSavedSentences() { List <string> sentances = new List <string>(); var sentencesInDb = _context.Sentences.Select(x => x.SentenceInRevert).ToList(); foreach (var item in sentencesInDb) { sentances.Add(RevertHelper.Revert(item)); } return(sentances); }