protected override DriverResult Display(PostalCodeSearchFormPart part, string displayType, dynamic shapeHelper)
        {
            var model = new PostalCodeSearchViewModel();

            return(ContentShape("Parts_AddressDirectory_PostalCodeSearchForm",
                                () =>
            {
                var shape = shapeHelper.Parts_AddressDirectory_PostalCodeSearchForm();
                shape.ContentPart = part;
                shape.ViewModel = model;
                return shape;
            }));
        }
        public ActionResult PostalCodeSearch(PagerParameters pagerParameters, string q = "")
        {
            // Strip spaces
            q = q.Replace(" ", "");
            Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters);
            IPageOfItems <IContent> searchHits = new PageOfItems <IContent>(new IContent[] { });

            try
            {
                searchHits = _addressDirectoryService.GetItemsByPostalCodeSearch(q, pager.Page, pager.PageSize);
            }
            catch (Exception e)
            {
                Logger.Error(e, "Invalid postal code search query: " + q);
            }

            var list = Shape.List();

            foreach (var contentItem in searchHits.Select(searchHit => searchHit.ContentItem))
            {
                // ignore search results which content item has been removed or unpublished
                if (contentItem == null)
                {
                    searchHits.TotalItemCount--;
                    continue;
                }
                list.Add(Services.ContentManager.BuildDisplay(contentItem, "Summary"));
            }

            var pagerShape = Shape.Pager(pager).TotalItemCount(searchHits.TotalItemCount);

            var searchViewModel = new PostalCodeSearchViewModel
            {
                Query          = q,
                TotalItemCount = searchHits.TotalItemCount,
                StartPosition  = (pager.Page - 1) * pager.PageSize + 1,
                EndPosition    = pager.Page * pager.PageSize > searchHits.TotalItemCount ? searchHits.TotalItemCount : pager.Page * pager.PageSize,
                ContentItems   = list,
                Pager          = pagerShape
            };

            //todo: deal with page requests beyond result count

            return(View((object)searchViewModel));
        }