Esempio n. 1
0
        List <SPTaggableList> GetModel(ClientContext ctx, AppWebHelper hlp)
        {
            List <SPTaggableList> model = null;

            try
            {
                model = new List <SPTaggableList>();
                LogHelper.Log("Inside getmodel");
                if (ctx != null)
                {
                    ListCollection lists = ctx.Web.Lists;

                    ctx.Load(lists, ListQuery => ListQuery.Include(
                                 l => l.Id, l => l.Title, l => l.BaseType,
                                 l => l.Fields.Where(
                                     f => f.TypeAsString == "TaxonomyFieldTypeMulti" || f.TypeAsString == "TaxonomyFieldType")
                                 ));

                    ctx.ExecuteQuery();

                    foreach (List list in lists)
                    {
                        if (list.BaseType == BaseType.DocumentLibrary && list.Fields.Count > 0)
                        {
                            SPTaggableList NewList = new SPTaggableList();
                            NewList.Title        = list.Title;
                            NewList.Id           = list.Id.ToString();
                            NewList.Disabled     = (hlp.ListsInfo.ContainsKey(NewList.Id) && hlp.ListsInfo[NewList.Id].ChildCount > 0) ? "Disabled" : string.Empty;
                            NewList.Asynchronous = (hlp.ListsInfo.ContainsKey(NewList.Id)) ? hlp.ListsInfo[NewList.Id].Asynchronous : true;

                            List <SPTaggableField> ListFields = new List <SPTaggableField>();
                            foreach (Field field in list.Fields)
                            {
                                TaxonomyField TaxField  = field as TaxonomyField;
                                string        key       = string.Concat(NewList.Id, "_", TaxField.Id.ToString());
                                var           isEnabled = hlp.CurrentlyEnabledFields.Where(c => c["Title"].Equals(key)).SingleOrDefault();
                                ListFields.Add(new SPTaggableField
                                {
                                    Id             = TaxField.Id.ToString(),
                                    Title          = TaxField.Title,
                                    TaggingEnabled = (isEnabled != null) ? true : false
                                });
                            }
                            NewList.Fields = ListFields;
                            model.Add(NewList);
                        }
                    }
                }

                return(model);
            }
            catch (Exception ex)
            {
                LogHelper.Log(ex.Message + ex.StackTrace);
                throw;
            }
        }