예제 #1
0
        public async Task <ActionResult> Index(string q = null, int p = 1)
        {
            ViewBag.Query = q;
            ViewBag.Title = string.Format("「{0}」の検索結果", q);

            var model = new SearchResultModel {
                Query = q
            };

            var condition = new SearchCondition(q);

            try
            {
                var skip = MaxItemsOnPage * (p - 1);
                var ids  = await _searchService.SearchItemIdAsync(condition);

                var count = ids.Count();

                ViewBag.CurrentPage     = p;
                ViewBag.HasPreviousPage = (p > 1);
                ViewBag.HasNextPage     = (count > MaxItemsOnPage * p);

                var items = await _itemDbCommand.GetByIdsAsync(ids, skip, MaxItemsOnPage);

                model.Items = Mapper.Map <IEnumerable <ItemIndexModel> >(items);
            }
            catch (Exception exception)
            {
                _logger.Error(exception);
                model.HasSearchServiceError = true;
            }

            return(View(model));
        }