public ActionResult Tournament(String guid, String inviteCode) { int tournamentId = ConvertToInt(guid); Models.Tournament tourny = new Models.Tournament(service, tournamentId); if (tournamentId == 0) { Session["Message"] = "This tournament is invalid."; Session["Message.Class"] = ViewError.ERROR; return(RedirectToAction("Index", "Tournament")); } if (tourny.Model != null) { bool isAdmin = tourny.IsAdmin(account.Model.AccountID); bool isParticipant = tourny.IsParticipent(account.Model.AccountID); // Should we check for registrations or view the tournament? if (!tourny.Model.InProgress && !isAdmin) { // Verify if the user has an invite code or the invite code is valid if (tourny.Model.PublicRegistration || tourny.Model.InviteCode == inviteCode) { TournamentRegisterViewModel fields = new TournamentRegisterViewModel() { AccountID = account.Model.AccountID, TournamentID = tourny.Model.TournamentID }; // Allow the tournament registration to be shown ViewBag.Tournament = tourny.Model; ViewBag.isRegistered = tourny.isRegistered(account.Model.AccountID); ViewBag.CanRegister = tourny.CanRegister(); return(View("RegisterForm", fields)); } else { Session["Message"] = "This tournament is not accepting registrations."; Session["Message.Class"] = ViewError.WARNING; } } else { // Verify if the user is allowed to view the tournament if (tourny.Model.PublicViewing || tourny.Model.InviteCode == inviteCode || isAdmin || isParticipant) { return(View("Tournament", tourny)); } else { Session["Message"] = "This tournament is not available to view."; Session["Message.Class"] = ViewError.WARNING; } } } else { Session["Message"] = "The tournament you're looking for doesn't exist or is not publicly shared."; Session["Message.Class"] = ViewError.WARNING; } return(RedirectToAction("Search", "Tournament")); }