// localhost:5000/secrets public IActionResult Index() { // create SecretsIndex model SecretsIndex viewModel = new SecretsIndex() { RecentSecrets = _context.secrets.Include(s => s.Likes).OrderByDescending(s => s.created_at).ToList(), ActiveUserId = _loggedUserId }; // and pass it to View! return(View(viewModel)); }
// localhost:5000/secrets public IActionResult Index() { // create SecretsIndex model SecretsIndex viewModel = new SecretsIndex() { RecentSecrets = _context.secrets.Include(s => s.Likes).ToList(), ActiveUserId = (int)HttpContext.Session.GetInt32("id") }; // and pass it to View! return(View(viewModel)); }
public IActionResult CreateSecret(SecretsIndex model) { Secret newSecret = model.NewSecret; if (ModelState.IsValid) { _context.secrets.Add(newSecret); _context.SaveChanges(); return(RedirectToAction("Index")); } model.ActiveUserId = _loggedUserId; model.RecentSecrets = _context.secrets.Include(s => s.Likes).OrderByDescending(s => s.created_at).ToList(); return(View("Index", model)); }
public IActionResult CreateSecret(SecretsIndex model) { Secret newSecret = model.NewSecret; if (ModelState.IsValid) { _context.secrets.Add(newSecret); _context.SaveChanges(); return(RedirectToAction("Index")); } model.ActiveUserId = (int)HttpContext.Session.GetInt32("id"); model.RecentSecrets = _context.secrets.Include(s => s.Likes).ToList(); return(View("Index", model)); }