public ActionResult Show(string id) { ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = AppUserState; // Since this is our default handler anything invalid will // run through here. No path - go to new if (string.IsNullOrEmpty(id) || id == "0") return this.New(); using (busCodeSnippet busSnippet = new busCodeSnippet()) { var snippet = busSnippet.Load(id); if (snippet == null) { return this.DisplayErrorPage("Invalid Snippet Id specified", "You specified a snippet id or link that is invalid and cannot be displayed. " + "Please using the <a href='./recent' class='hoverbutton'>Recent Snippets</a> or " + "<a href='mysnippets' class='hoverbutton'>My Snippets</a> buttons to look up valid snippets.", null); } bool allowWordWrap = false; bool showLineNumbers = busSnippet.Entity.ShowLineNumbers; string ua = Request.UserAgent.ToLower(); if (ua.Contains("iphone") || ua.Contains("blackberry") || ua.Contains("mobile")) { allowWordWrap = true; showLineNumbers = false; } // Update the code so it's formatted model.FormattedCode = busSnippet.Entity.FormattedCode; if (!AppUserState.IsEmpty()) model.IsFavoritedByUser = busSnippet.IsFavorite(busSnippet.Entity.Id, AppUserState.UserId); if (!string.IsNullOrEmpty(AppUserState.UserId) && AppUserState.UserId == busSnippet.Entity.UserId || AppUserState.IsAdmin) model.AllowEdit = true; // explicitly load up comments busSnippet.Entity.Comments = busSnippet.GetComments(); // For API result we have to make sure email and password are not included if (!string.IsNullOrEmpty(Format) && snippet.User != null) { busSnippet.StripSensitiveUserInformation(); } if (snippet.User != null) { if (!string.IsNullOrEmpty(snippet.User.Theme)) model.Theme = snippet.User.Theme; } ActionResult actionResult = this.ApiResult(busSnippet.Entity); if (actionResult != null) return actionResult; model.Snippet = busSnippet.Entity; // Fix up for Ace Editor model.Snippet.Language = busSnippet.FixUpLanguage(model.Snippet.Language).ToLower(); // Log views for all but poster if (model.Snippet.User == null || model.Snippet.User.Id != AppUserState.UserId) busSnippet.LogSnippetView(busSnippet.Entity.Id, Request.UserHostAddress, Request.UserAgent); return View("Show",model); } }
public ActionResult Show(string id) { ShowSnippetViewModel model = new ShowSnippetViewModel(this); model.AppUserState = AppUserState; // Since this is our default handler anything invalid will // run through here. No path - go to new if (string.IsNullOrEmpty(id) || id == "0") { return(this.New()); } using (busCodeSnippet busSnippet = new busCodeSnippet()) { var snippet = busSnippet.Load(id); if (snippet == null) { return(this.DisplayErrorPage("Invalid Snippet Id specified", "You specified a snippet id or link that is invalid and cannot be displayed. " + "Please using the <a href='./recent' class='hoverbutton'>Recent Snippets</a> or " + "<a href='mysnippets' class='hoverbutton'>My Snippets</a> buttons to look up valid snippets.", null)); } bool allowWordWrap = false; bool showLineNumbers = busSnippet.Entity.ShowLineNumbers; string ua = Request.UserAgent.ToLower(); if (ua.Contains("iphone") || ua.Contains("blackberry") || ua.Contains("mobile")) { allowWordWrap = true; showLineNumbers = false; } // Update the code so it's formatted model.FormattedCode = busSnippet.Entity.FormattedCode; if (!AppUserState.IsEmpty()) { model.IsFavoritedByUser = busSnippet.IsFavorite(busSnippet.Entity.Id, AppUserState.UserId); } if (!string.IsNullOrEmpty(AppUserState.UserId) && AppUserState.UserId == busSnippet.Entity.UserId || AppUserState.IsAdmin) { model.AllowEdit = true; } // explicitly load up comments busSnippet.Entity.Comments = busSnippet.GetComments(); // For API result we have to make sure email and password are not included if (!string.IsNullOrEmpty(Format) && snippet.User != null) { busSnippet.StripSensitiveUserInformation(); } if (snippet.User != null) { if (!string.IsNullOrEmpty(snippet.User.Theme)) { model.Theme = snippet.User.Theme; } } ActionResult actionResult = this.ApiResult(busSnippet.Entity); if (actionResult != null) { return(actionResult); } model.Snippet = busSnippet.Entity; // Fix up for Ace Editor model.Snippet.Language = busSnippet.FixUpLanguage(model.Snippet.Language).ToLower(); // Log views for all but poster if (model.Snippet.User == null || model.Snippet.User.Id != AppUserState.UserId) { busSnippet.LogSnippetView(busSnippet.Entity.Id, Request.UserHostAddress, Request.UserAgent); } return(View("Show", model)); } }