public ViewResult Index() { var initialModel = new SubmitFormViewModel { NumParagraphs = 5 }; return(View(initialModel)); }
public ViewResult Index(SubmitFormViewModel model) { if (ModelState.IsValid) { model.GeneratedParagraphs = _paragraphService.GetParagraphs(model.NumParagraphs, model.StartWithBaseballIpsum); } return(View(model)); }
public ViewResult Index(SubmitFormViewModel model) { model.GeneratedParagraphs = _corpusGenerator.GenerateParagraphs( model.NumParagraphs, model.StartWithBaseballIpsum); return(View(model)); }
public ViewResult Index(SubmitFormViewModel model) { Random random = new Random(); List <string> words = GetWords(); model.GeneratedParagraphs = GetCorpus(model.NumParagraphs, random, words); if (model.StartWithBaseballIpsum) { ModifyFirstParagraph(model); } return(View(model)); }
private static void ModifyFirstParagraph(SubmitFormViewModel model) { // get the first paragraph var firstSentence = model.GeneratedParagraphs[0]; // split it into individual words var firstSentenceWords = firstSentence.Split(' '); // replace the first five words firstSentenceWords[0] = "Baseball"; firstSentenceWords[1] = "ipsum"; firstSentenceWords[2] = "dolor"; firstSentenceWords[3] = "sit"; firstSentenceWords[4] = "amet"; // replace the first paragraph with the modified one model.GeneratedParagraphs[0] = string.Join(" ", firstSentenceWords); }
public async Task <IActionResult> SubmitForm(SubmitFormViewModel model) { var currentUser = await this.userManager.GetUserAsync(User); if (currentUser == null) { this.TempData.AddErrorMessage("Invalid user authentication."); return(RedirectToAction(nameof(SubmitForm))); } string ext = System.IO.Path.GetExtension(model.Image.FileName).ToLower(); var lenght = model.Image.Length; if (!(ext == ".jpg" || ext == ".png" || ext == ".jpeg")) { ModelState.AddModelError(string.Empty, "File uploaded is not an image, please use .jpg/.jpeg/.png file"); } if (lenght > 2000000) { ModelState.AddModelError(string.Empty, "File uploaded is too big maximum size is 2mb"); } if (!ModelState.IsValid) { return(View(model)); } peopleService.SubmitForm( model.Id, currentUser.Id, model.PoliceDepartment, model.Subject, model.Message, currentUser.Email, model.Image); TempData.AddSuccessMessage("Form was sent to secretariat, you will be notified soon about the outcome"); return(RedirectToAction(nameof(Details), new { id = model.Id })); }
public ViewResult Index(SubmitFormViewModel model) { // all the words in the dictionary Random random = new Random(); List <string> words = new List <string>(); // read in all the words to a List GetFromFile(words); // populate the viewmodel with an empty list of sentences model.GeneratedParagraphs = new List <string>(); for (int i = 0; i < model.NumParagraphs; i++) { var paragraph = string.Empty; var numSentences = random.Next(6, 7); // 6 or 7 sentences var commaSentence = random.Next(0, numSentences); // one comma in the paragraph randomly for (int j = 0; j < numSentences; j++) { var numWords = random.Next(7, 10); // from 7 to 10 words per sentence for (int k = 0; k < numWords; k++) { var word = words[random.Next(0, words.Count - 1)]; if (k == 0) { // uppercase the first letter of the first word var wordArray = word.ToCharArray(); wordArray[0] = char.ToUpper(wordArray[0]); paragraph += new string(wordArray); } else { paragraph += word; } // add a comma after the 5th word once per paragraph if (k == commaSentence && k == 4) { paragraph += ","; } paragraph += " "; } paragraph = paragraph.Trim(); paragraph += ". "; } model.GeneratedParagraphs.Add(paragraph.Trim()); } // if the user wants to start with "baseball ipsum dolor sit amet" if (model.StartWithBaseballIpsum) { // get the first paragraph var firstSentence = model.GeneratedParagraphs[0]; // split it into individual words var firstSentenceWords = firstSentence.Split(' '); // replace the first five words firstSentenceWords[0] = "Baseball"; firstSentenceWords[1] = "ipsum"; firstSentenceWords[2] = "dolor"; firstSentenceWords[3] = "sit"; firstSentenceWords[4] = "amet"; // replace the first paragraph with the modified one model.GeneratedParagraphs[0] = string.Join(" ", firstSentenceWords); } return(View(model)); }