Guest User

Untitled

a guest
Jul 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. public IActionResult Details(string id)
  2. {
  3. if (string.IsNullOrWhiteSpace(id))
  4. return RedirectToAction("index", "home");
  5.  
  6. var selectedCfp = _cfpContext.Cfps.SingleOrDefault(cfp => cfp.Slug == id);
  7.  
  8. if (selectedCfp == null)
  9. {
  10. // Check it the id happens to be a Guid
  11. if (Guid.TryParse(id, out Guid guidId))
  12. {
  13. if (guidId != Guid.Empty)
  14. selectedCfp = _cfpContext.Cfps.SingleOrDefault(cfp => cfp.Id == guidId);
  15. }
  16.  
  17. if (selectedCfp == null)
  18. // TODO to error page?
  19. return RedirectToAction("index", "home");
  20. }
  21.  
  22. // ... Non relevant code
  23.  
  24. return View(selectedCfp);
  25. }
Add Comment
Please, Sign In to add comment