public WordModels GetRandomWord() { Random rand = new Random(); List <WordModels> wordsList = ReadWordsFromFile(); int wordsCount = wordsList.Count; int randId = rand.Next(1, wordsCount); WordModels word = wordsList.FirstOrDefault(m => m.Id == randId); word.WordForGame += word.WordText.FirstOrDefault(); for (int i = 1; i < word.WordText.Length - 1; i++) { if (word.WordText[i + 1] == ' ') { word.WordForGame += " " + word.WordText[i] + " "; word.WordForGame += " " + word.WordText[i + 2]; i += 2; } else { word.WordForGame += " _"; } } word.WordForGame += " " + word.WordText.LastOrDefault(); return(word); }
public ActionResult Edit(WordModels model) { // Improvement necessary model.UserId = User.Identity.GetUserId(); ModelState["UserId"].Errors.Clear(); if (ModelState.IsValid) { _context.Entry(model).State = EntityState.Modified; _context.SaveChanges(); return(RedirectToAction("List")); } return(View(model)); }
public ActionResult Add(WordModels model) { // Improvement necessary model.UserId = User.Identity.GetUserId(); ModelState["UserId"].Errors.Clear(); if (!ModelState.IsValid) { return(View(new WordModels())); } _context.Words.Add(model); _context.SaveChanges(); return(RedirectToAction("List", "Word")); }