Exemplo n.º 1
0
        public async Task <IField> AddTaxonomyMultiAsync(string title, FieldTaxonomyOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            // Prep generic creation structure
            TaxonomyFieldCreationOptions creationOptions = new TaxonomyFieldCreationOptions
            {
                MultiValue  = true,
                TermStoreId = options.TermStoreId,
                TermSetId   = options.TermSetId
            };

            creationOptions.ImportFromCommonFieldOptions(title, options);

            // Step 1: create the field
            var newField = await AddFieldAsync(creationOptions).ConfigureAwait(false);

            // Step 2: make it a taxonomy field (depends on CSOM)
            await WireUpTaxonomyFieldAsync(newField as Field, creationOptions).ConfigureAwait(false);

            return(newField);
        }
Exemplo n.º 2
0
        private async Task WireUpTaxonomyFieldAsync(Field field, TaxonomyFieldCreationOptions options)
        {
            var xmlPayload = BuildTaxonomyFieldUpdateXmlPayload(options, (this as IDataModelParent).Parent);

            if (!string.IsNullOrEmpty(xmlPayload))
            {
                var apiCall = new ApiCall(xmlPayload)
                {
                    Commit = true
                };
                await field.RawRequestAsync(apiCall, HttpMethod.Post).ConfigureAwait(false);
            }
        }
Exemplo n.º 3
0
        private async Task WireUpTaxonomyFieldAsync(Field field, TaxonomyFieldCreationOptions options)
        {
            string parentId = (Parent is IList) ? (Parent as IList).Id.ToString() : "";
            ProvisionTaxonomyFieldRequest request = new ProvisionTaxonomyFieldRequest(PnPContext.Site.Id.ToString(),
                                                                                      PnPContext.Web.Id.ToString(),
                                                                                      field.Id.ToString(),
                                                                                      parentId,
                                                                                      options.TermStoreId,
                                                                                      options.TermSetId);

            ApiCall updateCall = new ApiCall(new List <Services.Core.CSOM.Requests.IRequest <object> >()
            {
                request
            })
            {
                Commit = true,
            };

            await field.RawRequestAsync(updateCall, HttpMethod.Post).ConfigureAwait(false);
        }
Exemplo n.º 4
0
        private static string BuildTaxonomyFieldUpdateXmlPayload(TaxonomyFieldCreationOptions options, IDataModelParent parent)
        {
            string xml = CsomHelper.TaxonomyFieldUpdate;

            xml = xml.Replace(CsomHelper.ListFieldId, (parent is IList) ? CsomHelper.TaxonomyFieldListObjectId : "");
            xml = xml.Replace(CsomHelper.TermStoreId, $"{{{options.TermStoreId}}}");
            xml = xml.Replace(CsomHelper.TermSetId, $"{{{options.TermSetId}}}");

            int counter = 10;

            xml = xml.Replace(CsomHelper.Counter, counter.ToString());
            counter++;
            xml = xml.Replace(CsomHelper.Counter2, counter.ToString());
            counter++;
            xml = xml.Replace(CsomHelper.Counter3, counter.ToString());
            counter++;
            xml = xml.Replace(CsomHelper.Counter4, counter.ToString());
            counter++;
            xml = xml.Replace(CsomHelper.Counter5, counter.ToString());

            return(xml);
        }