public IActionResult AddWord(string SecretWord) { SecretWordModel newWord = new SecretWordModel(); newWord.TimeStamp = DateTime.Now; newWord.Username = User.Identity.Name; newWord.Word = SecretWord; db.SecretWord.Add(newWord); db.SaveChanges(); return(Redirect(@"/Home/Index")); }
public IActionResult Index() { if (!db.SecretWord.Any()) { SecretWordModel defaultWord = new SecretWordModel(); defaultWord.TimeStamp = DateTime.Now; defaultWord.Username = User.Identity.Name; defaultWord.Word = "doctor"; db.SecretWord.Add(defaultWord); db.SaveChanges(); return(View(defaultWord)); } else { var word = db.SecretWord .OrderByDescending(am => am.TimeStamp).First(); return(View(word)); } }