Ejemplo n.º 1
0
        public ActionResult FeaturedArticle()
        {
            BlogViewModel model = null;

            try
            {
                IBlog blog = _renderingRepository.GetDataSourceItem <IBlog>();
                if (blog != null)
                {
                    model = _blogViewModelConverter.ConvertTo(blog, true);
                    System.Web.HttpContext.Current.Items.Add(Constants.featuredArticleID, blog.Id.ToString());
                }
                else
                {
                    string category    = HttpUtility.UrlDecode(System.Web.HttpContext.Current.Request.QueryString[Constants.categoryQueryString]);
                    var    searchQuery = new SearchQuery {
                        NoOfResults = Constants.PageSize_One, Page = Constants.IntialPageNo, Category = string.IsNullOrEmpty(category) ? category : category.ToLower()
                    };
                    var blogList = _searchContextManager.GetBlogs(searchQuery, true);
                    if (blogList != null && blogList.Any())
                    {
                        model = blogList.First();
                        System.Web.HttpContext.Current.Items.Add(Constants.featuredArticleID, model.BlogId);
                    }
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error(ex.Message, ex, this);
            }
            return(View(Constants.FeaturedArticle, model));
        }
Ejemplo n.º 2
0
        public ActionResult SearchResults(string query)
        {
            BlogListViewModel model = new BlogListViewModel();

            try
            {
                if (!string.IsNullOrEmpty(query))
                {
                    var searchQuery = new SearchQuery {
                        NoOfResults = Constants.NoOfBlogs, Page = Constants.IntialPageNo, SearchText = query
                    };
                    model.Blogs = _searchContextManager.GetBlogs(searchQuery);
                }
            }
            catch (Exception ex)
            {
                Sitecore.Diagnostics.Log.Error(ex.Message, ex, this);
            }
            return(View(Constants.SearchResultsViewName, model));
        }