Ejemplo n.º 1
0
    public static MvcHtmlString TreeView(this HtmlHelper htmlHelper, TermsetModel termset)
    {
        string           termsetDisplayName = termset.DisplayName;
        List <TermModel> terms = termset.TopLevelTerms;

        string html = "<div>" +
                      "<ul class='treeview'>" +
                      "<li  class='closed expandable'>" +
                      "<span class='open expandable'>" + termsetDisplayName + "</span>";

        if (terms.Count > 0)
        {
            html += "<ul>";
            foreach (var term in terms)
            {
                html += "<li  class='closed expandable'>" +
                        "<span>" + term.TermName + "</span>" +
                        GetChildTerms(term) +
                        "</li>";
            }
            html += "<ul>";
        }


        html += "</li>" +
                "</ul>" +
                "</div>";

        return(MvcHtmlString.Create(html));
    }
Ejemplo n.º 2
0
  public static MvcHtmlString TreeView(this HtmlHelper htmlHelper, TermsetModel termset) {

    string termsetDisplayName = termset.DisplayName;
    List<TermModel> terms = termset.TopLevelTerms;

    string html = "<div>" +
                  "<ul class='treeview'>" +
                  "<li  class='closed expandable'>" +
                  "<span class='open expandable'>" + termsetDisplayName + "</span>";
    
    if (terms.Count > 0) {
      html += "<ul>";
      foreach (var term in terms) {
        html += "<li  class='closed expandable'>" + 
                "<span>" + term.TermName + "</span>" + 
                GetChildTerms(term) +
                "</li>";
      }
      html += "<ul>";
    }
    
    
    html += "</li>" + 
            "</ul>" +
            "</div>";

    return MvcHtmlString.Create(html);
  }
Ejemplo n.º 3
0
    public static SiteCollectionModel GetSiteCollectionModel(string url)
    {
        SiteCollectionModel model = new SiteCollectionModel();

        var aspnetHttpContext = System.Web.HttpContext.Current;
        var spContext         = SharePointContextProvider.Current.GetSharePointContext(aspnetHttpContext);

        using (var clientContext = spContext.CreateUserClientContextForSPHost()) {
            if (clientContext != null)
            {
                Site siteCollection = clientContext.Site;
                clientContext.Load(siteCollection, sc => sc.Url);
                clientContext.ExecuteQuery();
                model.Url = siteCollection.Url;

                TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
                taxonomySession.UpdateCache();
                clientContext.Load(taxonomySession, ts => ts.TermStores);
                clientContext.ExecuteQuery();
                TermStore termStore        = taxonomySession.TermStores.FirstOrDefault <TermStore>();
                Guid      localTermStoreID = termStore.Id;
                TermGroup group            = termStore.GetSiteCollectionGroup(siteCollection, false);
                clientContext.ExecuteQuery();
                bool siteCollectionHasPrivateGroup = CSOMObjectExists(group);
                model.hasPrivateGroup = siteCollectionHasPrivateGroup;
                model.Termsets        = new Dictionary <Guid, TermsetModel>();
                if (siteCollectionHasPrivateGroup)
                {
                    clientContext.Load(group, g => g.Id, g => g.Name, g => g.TermSets);
                    clientContext.ExecuteQuery();
                    model.GroupId   = group.Id;
                    model.GroupName = group.Name;
                    foreach (var ts in group.TermSets)
                    {
                        TermsetModel termset = new TermsetModel {
                            TermsetId = ts.Id, DisplayName = ts.Name
                        };
                        clientContext.Load(ts.Terms);
                        clientContext.ExecuteQuery();
                        List <TermModel> terms = new List <TermModel>();
                        foreach (Term term in ts.Terms)
                        {
                            TermModel newTerm = new TermModel {
                                TermName = term.Name, TermId = term.Id
                            };
                            LoadChildTerms(term, newTerm, clientContext);
                            terms.Add(newTerm);
                        }
                        termset.TopLevelTerms = terms;
                        model.Termsets.Add(ts.Id, termset);
                    }
                }
            }
            return(model);
        }
    }
Ejemplo n.º 4
0
  public static SiteCollectionModel GetSiteCollectionModel(string url) {
    
    SiteCollectionModel model = new SiteCollectionModel();

    var aspnetHttpContext = System.Web.HttpContext.Current;
    var spContext = SharePointContextProvider.Current.GetSharePointContext(aspnetHttpContext);

    using (var clientContext = spContext.CreateUserClientContextForSPHost()) {
      if (clientContext != null) {

        Site siteCollection = clientContext.Site;
        clientContext.Load(siteCollection, sc => sc.Url);
        clientContext.ExecuteQuery();
        model.Url = siteCollection.Url;

        TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(clientContext);
        taxonomySession.UpdateCache();
        clientContext.Load(taxonomySession, ts => ts.TermStores);
        clientContext.ExecuteQuery();
        TermStore termStore = taxonomySession.TermStores.FirstOrDefault<TermStore>();
        Guid localTermStoreID = termStore.Id;
        TermGroup group = termStore.GetSiteCollectionGroup(siteCollection, false);
        clientContext.ExecuteQuery();
        bool siteCollectionHasPrivateGroup = CSOMObjectExists(group);
        model.hasPrivateGroup = siteCollectionHasPrivateGroup;
        model.Termsets = new Dictionary<Guid, TermsetModel>();
        if (siteCollectionHasPrivateGroup) {
          clientContext.Load(group, g => g.Id, g => g.Name, g => g.TermSets);
          clientContext.ExecuteQuery();
          model.GroupId = group.Id;
          model.GroupName = group.Name;
          foreach (var ts in group.TermSets) {
            TermsetModel termset = new TermsetModel { TermsetId = ts.Id, DisplayName = ts.Name };
            clientContext.Load(ts.Terms);
            clientContext.ExecuteQuery();
            List<TermModel> terms = new List<TermModel>();
            foreach (Term term in ts.Terms) {
              TermModel newTerm = new TermModel { TermName = term.Name, TermId = term.Id };
              LoadChildTerms(term, newTerm, clientContext);
              terms.Add(newTerm);
            }
            termset.TopLevelTerms = terms;
            model.Termsets.Add(ts.Id, termset);
          }
        }
        
      }
      return model;
    }

  }