예제 #1
0
 /// <summary>
 /// Allows searching of snippets by providing a search parameter structure
 /// </summary>
 /// <returns></returns>
 public List <CodeSnippetListItem> SearchSnippets(CodeSnippetSearchParameters searchParameters)
 {
     using (busCodeSnippet codeSnippet = CodePasteFactory.GetCodeSnippet())
     {
         return(codeSnippet.GetSearchList(searchParameters).ToList());
     }
 }
예제 #2
0
        public ActionResult Search(FormCollection formVars)
        {
            ListSnippetViewModel model = new ListSnippetViewModel(this);
            model.AppUserState = this.AppUserState;
            model.ErrorDisplay = this.ErrorDisplay;
            model.PageTitle = "Search Code Snippets";
            
            model.SearchOrderItems = AppWebUtils.GetSelectListFromEnum(typeof(SearchOrderTypes), "Entered");

            using (busCodeSnippet busSnippet = new busCodeSnippet())
            {
                model.Controller = this;
                model.busSnippet = busSnippet;

                model.Parameters = new CodeSnippetSearchParameters();

                this.TryUpdateModel(model.Parameters);

                var snippetList = busSnippet.GetSearchList(model.Parameters);
                int snippetListCount = 0;
                if (snippetList != null)
                    snippetListCount = snippetList.Count();

                if (formVars.Count > 0)
                {
                    if (snippetList == null)
                        this.ErrorDisplay.ShowError("Please provide at least one search criterion.");
                    else if (snippetListCount < 1)
                        this.ErrorDisplay.ShowError("No matches found for your search criteria.");
                }

                if (snippetList != null)
                {
                    model.Paging = new PagingDetails();
                    model.Paging.PageCount = (int)Math.Ceiling(Convert.ToDecimal(snippetListCount) / Convert.ToDecimal(model.Paging.PageSize));

                    int.TryParse(Request.Params["page"] ?? "1", out model.Paging.Page);

                    if (model.Paging.Page > 0 && snippetListCount > model.Paging.PageSize)
                    {
                        snippetList = snippetList.Skip((model.Paging.Page - 1) * model.Paging.PageSize)
                                                 .Take(model.Paging.PageSize);
                    }
                    model.SnippetList = snippetList.ToList();
                }
                else
                    model.SnippetList = new List<CodeSnippetListItem>();


                ActionResult result = this.ApiResult(model.SnippetList);
                if (result != null)
                    return result;
            }

            return View("Search",model);
        }
예제 #3
0
        public ActionResult Search(FormCollection formVars)
        {
            ListSnippetViewModel model = new ListSnippetViewModel(this);

            model.AppUserState = this.AppUserState;
            model.ErrorDisplay = this.ErrorDisplay;
            model.PageTitle    = "Search Code Snippets";

            model.SearchOrderItems = AppWebUtils.GetSelectListFromEnum(typeof(SearchOrderTypes), "Entered");

            using (busCodeSnippet busSnippet = new busCodeSnippet())
            {
                model.Controller = this;
                model.busSnippet = busSnippet;

                model.Parameters = new CodeSnippetSearchParameters();

                this.TryUpdateModel(model.Parameters);

                var snippetList      = busSnippet.GetSearchList(model.Parameters);
                int snippetListCount = 0;
                if (snippetList != null)
                {
                    snippetListCount = snippetList.Count();
                }

                if (formVars.Count > 0)
                {
                    if (snippetList == null)
                    {
                        this.ErrorDisplay.ShowError("Please provide at least one search criterion.");
                    }
                    else if (snippetListCount < 1)
                    {
                        this.ErrorDisplay.ShowError("No matches found for your search criteria.");
                    }
                }

                if (snippetList != null)
                {
                    model.Paging           = new PagingDetails();
                    model.Paging.PageCount = (int)Math.Ceiling(Convert.ToDecimal(snippetListCount) / Convert.ToDecimal(model.Paging.PageSize));

                    int.TryParse(Request.Params["page"] ?? "1", out model.Paging.Page);

                    if (model.Paging.Page > 0 && snippetListCount > model.Paging.PageSize)
                    {
                        snippetList = snippetList.Skip((model.Paging.Page - 1) * model.Paging.PageSize)
                                      .Take(model.Paging.PageSize);
                    }
                    model.SnippetList = snippetList.ToList();
                }
                else
                {
                    model.SnippetList = new List <CodeSnippetListItem>();
                }


                ActionResult result = this.ApiResult(model.SnippetList);
                if (result != null)
                {
                    return(result);
                }
            }

            return(View("Search", model));
        }