Exemplo n.º 1
0
        /// <summary>
        /// /list/recent
        /// /list/tag/C#
        /// </summary>
        /// <param name="listAction"></param>
        /// <param name="listFilter"></param>
        /// <returns></returns>
        public ActionResult List(string listAction, string listFilter)
        {
            if (listAction == "MySnippets")
            {
                return(MySnippets());
            }
            else if (listAction == "MyFavorites")
            {
                return(MyFavorites());
            }

            using (busCodeSnippet busSnippet = new busCodeSnippet())
            {
                var snippetList = busSnippet.GetSnippetList(listAction, listFilter);
                busSnippet.Dispose();


                //if (listAction == "recent")
                //{
                //    // keep the snippetlist short
                //    if (snippetList != null)
                //        snippetList = snippetList.Take(20).ToList();
                //}
                this.ViewData["busSnippet"]  = busSnippet;
                this.ViewData["SnippetList"] = snippetList;

                if (listAction == "tag")
                {
                    this.ViewData["PageTitle"] = "Recent snippets matching tags of " + listFilter;
                    if (snippetList.Count < 1)
                    {
                        Response.StatusCode = 404;
                        ErrorController.ShowErrorPage("Invalid tag", "You've entered a tag that is not valid or has no related entries.");
                    }
                }
                else if (listAction == "language")
                {
                    this.ViewData["PageTitle"] = "Recent snippets matching language of " + listFilter;
                }
                else if (listAction == "user")
                {
                    if (snippetList.Count > 0)
                    {
                        this.ViewData["PageTitle"] = "Recent snippets for: " + snippetList.First().Author;
                    }
                    else
                    {
                        this.ViewData["PageTitle"] = "Recent snippets for user: "******"List"));
            }
        }