コード例 #1
0
        public ActionResult Index()
        {
            var model = new MainModel
            {
                SavedSentences = SentencesService.GetSentences()
            };

            return(View(model));
        }
コード例 #2
0
        public ActionResult DeleteAllRecords()
        {
            SentencesService.DeleteSentences();

            var model = new MainModel
            {
                SavedSentences = SentencesService.GetSentences()
            };

            TempData["Message"] = "Sentences successfully deleted from Db";
            return(View(IndexView, model));
        }
コード例 #3
0
        public ActionResult Save(MainModel mainModel)
        {
            var sentencesToInsert = new List <Sentences>();

            string allText = new StreamReader(mainModel.File.InputStream).ReadToEnd();

            string[] allSentences = allText.Split(new Char[] { '.' });

            foreach (var sentence in allSentences)
            {
                if (sentence.Contains(mainModel.InputText))
                {
                    var reversedSentence      = Reverse(sentence);
                    var ifSentenceFromDbExist = SentencesService.IfSentenceExist(s => s.Text == reversedSentence && s.SearchWord == mainModel.InputText);

                    if (!ifSentenceFromDbExist)
                    {
                        var sentenceToInsert = FillParameterForInsert(reversedSentence, DateTime.Now, "Pavlo", mainModel.InputText);
                        sentencesToInsert.Add(sentenceToInsert);
                    }
                }
            }

            if (sentencesToInsert.Count != 0)
            {
                SentencesService.InsertSentences(sentencesToInsert);
                TempData["Message"] = "New sentences successfully inserted";
            }

            else
            {
                TempData["Message"] = "Noting to insert";
            }

            mainModel.SavedSentences = SentencesService.GetSentences();

            return(View(IndexView, mainModel));
        }