Пример #1
0
        public WikiArticleViewModelBase(
            RequestContext requestContext,
            ArticleId articleId,
            ArticleRevisionDate articleRevisionDate = null,
            HeaderTab activeTab = HeaderTab.None)
        {
            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }
            if (articleId == null)
            {
                throw new ArgumentNullException("articleId");
            }

            this.CurrentRepository = RepositoryRequestInstance.Get(requestContext);
            this.CurrentPrincipal  = requestContext.HttpContext.User;

            this.ArticleId           = articleId;
            this.DisplayArticleId    = articleId;
            this.ArticleRevisionDate = articleRevisionDate;
            this.ActiveTab           = activeTab;

            this.Article = this.CurrentRepository.GetArticle(articleId);

            this.CanEditArticle = (this.Article == null) || this.Article.CanEdit(this.CurrentPrincipal);
        }
Пример #2
0
        public WikiSearchViewModel(RequestContext requestContext, string searchTerm)
        {
            this.SearchTerm = searchTerm ?? string.Empty;

            var searchTermArticleId = new ArticleId(this.SearchTerm);

            this.SearchTermFormatted = Capitalize(searchTermArticleId.Title);

            var repository = RepositoryRequestInstance.Get(requestContext);

            var searchResult = repository.SearchArticles(this.SearchTerm);

            this.SearchResults = searchResult.Items.Select(x => new SearchItem(x)).ToList();
            this.Suggestions   = searchResult.Suggestions;

            var articleExists = repository.GetArticleExists(searchTermArticleId);

            this.ArticleExists = (articleExists != null);

            bool isRedirect = (articleExists != null) && (articleExists.Title != SearchTermFormatted);

            this.ArticleTitle = (articleExists != null)
                                    ? (isRedirect ? articleExists.Title : this.SearchTermFormatted)
                                    : this.SearchTermFormatted;

            this.ArticleRedirectedFromTitle = (articleExists != null && isRedirect) ? this.SearchTermFormatted : null;
        }