public ActionResult SearchResults(BoardsViewModel bvm)
        {
            int pageNumber = bvm.page ?? 1;

            if (bvm.search != null && bvm.search.Count() > 0)
            {
                Debug.WriteLine("Criteria Count: " + bvm.search.Count());
                var predicate = PredicateBuilder.True<Post>();
                foreach (SearchCriteria sc in bvm.search)
                {
                    if (sc != null)
                    {
                        if (!sc.verify())
                        {
                            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                        }
                        else
                        {
                            if (sc.isOr && predicate.ToString().Equals("f => True"))
                            {
                                predicate = PredicateBuilder.False<Post>();
                                Debug.WriteLine("False");
                            }
                            else if (predicate.ToString().Equals("f => True"))
                            {
                                Debug.WriteLine("True");
                            }
                            predicate = sc.filterPosts(predicate);
                        }
                    }
                    else
                    {
                        return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                    }
                }
                var Posts = db.Posts.AsExpandable().Where(predicate);
                Debug.WriteLine("Result Count: " + Posts.Count());
                foreach (Post p in Posts)
                {
                    Debug.WriteLine(p.entry);
                }
                List<BoardPostViewModel> l_bpvm = new List<BoardPostViewModel>();
                foreach (Post p in Posts.OrderByDescending(x => x.date_posted).ToList())
                {
                    l_bpvm.Add(GetBoardPostViewModel(p));
                }
                bvm.Posts = l_bpvm.ToPagedList(pageNumber, 10);
                bvm.search = bvm.search;
                return View(bvm);
            }
            else
            {
                return RedirectToAction("Boards", "Application");
            }
        }
 public ActionResult PagedSearchResults(string json)
 {
     if (json == null)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     else
     {
         BoardsViewModel bvm = new BoardsViewModel();
         try
         {
             bvm = JsonConvert.DeserializeObject<BoardsViewModel>(json, new JsonSerializerSettings()
             {
                 TypeNameHandling = TypeNameHandling.Objects
             });
         }
         catch (Exception)
         {
             return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
         }
         if (bvm != null && bvm.search != null && bvm.search.Count() > 0)
         {
             Debug.WriteLine("Criteria Count: " + bvm.search.Count());
             var predicate = PredicateBuilder.True<Post>();
             foreach (SearchCriteria sc in bvm.search)
             {
                 if (sc != null)
                 {
                     if (!sc.verify())
                     {
                         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                     }
                     else
                     {
                         if (sc.isOr && predicate.ToString().Equals("f => True"))
                         {
                             predicate = PredicateBuilder.False<Post>();
                             Debug.WriteLine("False");
                         }
                         else if (predicate.ToString().Equals("f => True"))
                         {
                             Debug.WriteLine("True");
                         }
                         predicate = sc.filterPosts(predicate);
                     }
                 }
                 else
                 {
                     return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
                 }
             }
             var Posts = db.Posts.AsExpandable().Where(predicate);
             Debug.WriteLine("Result Count: " + Posts.Count());
             foreach (Post p in Posts)
             {
                 Debug.WriteLine(p.entry);
             }
             List<BoardPostViewModel> l_bpvm = new List<BoardPostViewModel>();
             foreach (Post p in Posts.OrderByDescending(x => x.date_posted).ToList())
             {
                 l_bpvm.Add(GetBoardPostViewModel(p));
             }
             bvm.Posts = l_bpvm.ToPagedList(bvm.page ?? 1, 10);
             return View("SearchResults", bvm);
         }
         else
         {
             return RedirectToAction("Boards", "Application");
         }
     }
 }