Exemplo n.º 1
0
        public async Task <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx)
        {
            var latest = arguments["latest"].ToBooleanValue();
            var mode   = arguments["mode"].Or(arguments.At(0));

            if (mode.IsNil() || mode.ToStringValue() == "id")
            {
                var contentItemId = input.ToStringValue();
                var contentItem   = await _contentManager.GetAsync(contentItemId, latest?VersionOptions.Latest : VersionOptions.Published);

                return(FluidValue.Create(contentItem));
            }
            if (mode.ToStringValue() == "alias")
            {
                var contentItemId = await _contentAliasManager.GetContentItemIdAsync(input.ToStringValue());

                if (contentItemId != null)
                {
                    var contentItem = await _contentManager.GetAsync(contentItemId, latest?VersionOptions.Latest : VersionOptions.Published);

                    return(FluidValue.Create(contentItem));
                }
            }
            else if (mode.ToStringValue() == "version")
            {
                var contentItemVersionId = input.ToStringValue();
                var contentItem          = await _contentManager.GetVersionAsync(contentItemVersionId);

                return(FluidValue.Create(contentItem));
            }

            return(FluidValue.Create(null));
        }
Exemplo n.º 2
0
        public async Task <string> GetAdvFormSubmissionsCSVstring(IEnumerable <ContentItem> pageOfContentItems)
        {
            ContentItem selectedContent;
            Dictionary <string, dynamic> submissionHtml;
            List <string> column = new List <string>();

            column.Add("Form Name");
            column.Add("Submitted Date");
            column.Add("Created By");
            column.Add("Status");
            StringBuilder csv = new StringBuilder();

            foreach (var contentItem in pageOfContentItems)
            {
                csv.Append(string.Format("{0},", contentItem.Content.AutoroutePart.Path.ToString().Split("/")[1].Replace("-", " ")));
                csv.Append(string.Format("{0},", contentItem.CreatedUtc.Value));
                csv.Append(string.Format("{0},", contentItem.Owner));
                selectedContent = await _contentManager.GetAsync(contentItem.Content.AdvancedFormSubmissions.Status.Text.ToString(), VersionOptions.Published);

                if (selectedContent == null)
                {
                    selectedContent = await _contentManager.GetAsync(contentItem.Content.AdvancedFormSubmissions.Status.Text.ToString(), VersionOptions.DraftRequired);
                }
                csv.Append(string.Format("{0},", selectedContent != null && selectedContent.DisplayText != null ? selectedContent.DisplayText : string.Empty));
                submissionHtml = JsonConvert.DeserializeObject <Dictionary <string, dynamic> >(contentItem.Content.AdvancedFormSubmissions.Submission.Html.ToString());
                column.AddRange(this.GetNewColumns(submissionHtml, column));
                csv.Append(this.GetCSVString(submissionHtml, column));
                csv.AppendLine();
            }
            StringBuilder file = new StringBuilder(string.Join(",", column));

            file.AppendLine();
            file.Append(csv.ToString());
            return(file.ToString());
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Display(string contentItemId)
        {
            if (contentItemId == null)
            {
                return(NotFound());
            }

            var contentItem = await _contentManager.GetAsync(contentItemId);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewContent, contentItem))
            {
                return(this.ChallengeOrForbid());
            }
            //set to a global variable"
            //  _httpContextAccessor.HttpContext.Items["Content.CurrentContentItemId"] =contentItem.ContentItemId;
            // _httpContextAccessor.HttpContext.Items["CurrentContentItem"] =contentItem;

            var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, _updateModelAccessor.ModelUpdater);


            return(View(model));
        }
        public override IDisplayResult Edit(TaxonomyField field, BuildFieldEditorContext context)
        {
            return(Initialize <EditTagTaxonomyFieldViewModel>(GetEditorShapeType(context), async model =>
            {
                var settings = context.PartFieldDefinition.GetSettings <TaxonomyFieldSettings>();
                model.Taxonomy = await _contentManager.GetAsync(settings.TaxonomyContentItemId, VersionOptions.Latest);

                if (model.Taxonomy != null)
                {
                    var termEntries = new List <TermEntry>();
                    TaxonomyFieldDriverHelper.PopulateTermEntries(termEntries, field, model.Taxonomy.As <TaxonomyPart>().Terms, 0);
                    var tagTermEntries = termEntries.Select(te => new TagTermEntry
                    {
                        ContentItemId = te.ContentItemId,
                        Selected = te.Selected,
                        DisplayText = te.Term.DisplayText,
                        IsLeaf = te.IsLeaf
                    });

                    model.TagTermEntries = JsonConvert.SerializeObject(tagTermEntries, SerializerSettings);
                }

                model.Field = field;
                model.Part = context.ContentPart;
                model.PartFieldDefinition = context.PartFieldDefinition;
            }));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Display(string contentItemId, bool latest = false)
        {
            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Deployment.CommonPermissions.Export))
            {
                return(Forbid());
            }

            var contentItem = await _contentManager.GetAsync(contentItemId, latest == false?VersionOptions.Published : VersionOptions.Latest);

            if (contentItem == null)
            {
                return(NotFound());
            }

            // Export permission is required as the overriding permission.
            // Requesting EditContent would allow custom permissions to deny access to this content item.
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.EditContent, contentItem))
            {
                return(Forbid());
            }

            var model = new DisplayJsonContentItemViewModel
            {
                ContentItem     = contentItem,
                ContentItemJson = JObject.FromObject(contentItem).ToString()
            };

            return(View(model));
        }
        public async Task <IActionResult> NextContentItemInList(string currentContentItemId)
        {
            var allFlattendedNodes = await AllFlattendedNodes(currentContentItemId);


            //https://stackoverflow.com/questions/2680228/linq-next-item-in-list
            var index = allFlattendedNodes.FindIndex((x => x.Id == currentContentItemId));



            try {
                var nextContentItem = allFlattendedNodes[index + 1]; //next item in list by index
                if (nextContentItem == null)
                {
                    return(NotFound());
                }

                var displayRouteValues = (await _contentManager.PopulateAspectAsync <ContentItemMetadata>(nextContentItem.ContentItem)).DisplayRouteValues;
                return(RedirectToRoute(displayRouteValues));
            } catch (ArgumentOutOfRangeException) {
                //this means we are at end of list . notify user and stay on current item
                //throw new ArgumentOutOfRangeException("index", ex);
                var currentContentItem = await _contentManager.GetAsync(currentContentItemId, VersionOptions.Published);

                var currentContentdisplayRouteValues = (await _contentManager.PopulateAspectAsync <ContentItemMetadata>(currentContentItem))
                                                       .DisplayRouteValues;

                _notifier.Information(H["Already at the last list item."]);
                return(RedirectToRoute(currentContentdisplayRouteValues));
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Display(string alias)
        {
            if (String.IsNullOrWhiteSpace(alias))
            {
                await Index();
            }

            var contentItemId = await _contentAliasManager.GetContentItemIdAsync("slug:AdvancedForms/" + alias);

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Published);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewContent, contentItem))
            {
                return(Unauthorized());
            }

            var model = new AdvancedFormViewModel
            {
                Id           = contentItemId,
                Title        = contentItem.Content.AdvancedForm.Title,
                Container    = contentItem.Content.AdvancedForm.Container.Html,
                Description  = contentItem.Content.AdvancedForm.Description.Html,
                Instructions = contentItem.Content.AdvancedForm.Instructions.Html
            };

            return(View(model));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(string contentItemId, string returnUrl)
        {
            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageAdvancedForms, contentItem))
            {
                return(Unauthorized());
            }

            var model = new AdvancedFormViewModel
            {
                Id           = contentItemId,
                EntryType    = Enums.EntryType.Edit,
                Title        = contentItem.DisplayText,
                Container    = contentItem.Content.AdvancedForm.Container.Html,
                Description  = contentItem.Content.AdvancedForm.Description.Html,
                Instructions = contentItem.Content.AdvancedForm.Instructions.Html,
                Header       = contentItem.Content.AdvancedForm.Header.Html,
                Footer       = contentItem.Content.AdvancedForm.Footer.Html,
                Tag          = contentItem.Content.AdvancedForm.Tag.Text
            };

            return(View("Create", model));
        }
Exemplo n.º 9
0
        private async Task <IActionResult> CreatePOST(string id, string containerId, string returnUrl, CompleteActionOutCome onCompleteSubmitAction, Func <ContentItem, Task> conditionallyPublish)
        {
            var contentItem = await _contentManager.NewAsync(id);

            // Set the current user as the owner to check for ownership permissions on creation
            contentItem.Owner = User.Identity.Name;

            if (!await _authorizationService.AuthorizeAsync(User, CommonPermissions.EditContent, contentItem))
            {
                return(Unauthorized());
            }

            var model = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, true);

            if (!ModelState.IsValid)
            {
                _session.Cancel();
                return(View(model));
            }


            if (!string.IsNullOrEmpty(containerId))
            {
                //add parent content reference
                var rootContentItem = await _contentManager.GetAsync(containerId, VersionOptions.Latest);

                if (rootContentItem != null)
                {
                    await _listContainerService.AddChildContentItemReference(rootContentItem, contentItem);
                }
            }

            await _contentManager.CreateAsync(contentItem, VersionOptions.Draft);

            await conditionallyPublish(contentItem);



            return(await RedirectSelectActionResult(contentItem, onCompleteSubmitAction, returnUrl));


            /*if ((!string.IsNullOrEmpty(returnUrl)) && (stayOnSamePage))
             * {
             *  return LocalRedirect(returnUrl);
             * }
             *
             * var adminRouteValues = (await _contentManager.PopulateAspectAsync<ContentItemMetadata>(contentItem)).AdminRouteValues;
             *
             * if (!string.IsNullOrEmpty(returnUrl))
             * {
             *  adminRouteValues.Add("returnUrl", returnUrl);
             * }
             *
             * return RedirectToRoute(adminRouteValues);*/
        }
Exemplo n.º 10
0
        public async Task <ActionResult> Display(int id)
        {
            var contentItem = await _contentManager.GetAsync(id);

            if (contentItem == null)
            {
                return(NotFound());
            }

            return(View(contentItem));
        }
Exemplo n.º 11
0
        public async Task <JsonResult> UpdateTypeContents()
        {
            var temp = this.DeserializeObject <IEnumerable <NewPartVM> >();

            foreach (var item in temp)
            {
                ContentItem DevicesInfoContentItem = await _contentManager.GetAsync(item.NewID);

                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDisplayName = item.NewDisplayName);
                DevicesInfoContentItem.Alter <NewPart>(x => x.NewDescription = item.NewDescription);
                DevicesInfoContentItem.Alter <NewPart>(x => x.Classify       = item.Classify);
                item.Name = "ContentType_" + item.NewDisplayName;
                if (_contentDefinitionManager.GetTypeDefinition(item.Name) == null)
                {
                }
                else
                {
                    if (item.Classify == false)
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .DisplayedAs(item.NewDisplayName)
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart")
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting))
                                                                      );
                    }
                    else
                    {
                        var BodyPartSetting = new BodyPartSettings {
                        };
                        BodyPartSetting.Editor = "Wysiwyg";
                        _contentDefinitionManager.AlterTypeDefinition(item.Name, bulid => bulid
                                                                      .DisplayedAs(item.NewDisplayName)
                                                                      .Draftable()
                                                                      .Creatable()
                                                                      .Listable()
                                                                      .WithPart("TitlePart", part => part.WithPosition("2"))
                                                                      .WithPart("BodyPart", part => part.WithSettings(BodyPartSetting).WithPosition("3"))
                                                                      .WithPart("TypeNewClassifyPart", part => part.WithPosition("1"))
                                                                      );
                    }
                }
                DevicesInfoContentItem.Alter <NewPart>(x => x.Name    = item.Name);
                DevicesInfoContentItem.Alter <TitlePart>(x => x.Title = item.NewDisplayName);
                _contentDefinitionManager.GetTypeDefinition(item.Name);
                _session.Save(DevicesInfoContentItem);
            }
            return(this.Jsonp(temp));
        }
Exemplo n.º 12
0
        public async Task <IActionResult> GetById(string id)
        {
            var contentItem = await _contentManager.GetAsync(id);

            if (contentItem == null)
            {
                return(NotFound());
            }

            return(new ObjectResult(contentItem));
        }
Exemplo n.º 13
0
        public async Task <ContentTreeItem> BuildContentTreebByRootContentItemIdAsync(string rootContentItemId, string selectedContentItemId)
        {
            //this will get all records with one sql query
            var rootContentItem = await _contentManager.GetAsync(rootContentItemId);

            var urlHelperFactory = _serviceProvider.GetRequiredService <IUrlHelperFactory>();

            _urlHelper = urlHelperFactory.GetUrlHelper(_actionContextAccessor.ActionContext);

            return(await BuildContentTreeByRootContentItem(rootContentItem, selectedContentItemId));
        }
Exemplo n.º 14
0
        public async Task <ActionResult> Display(string contentItemId)
        {
            var contentItem = await _contentManager.GetAsync(contentItemId);

            if (contentItem == null)
            {
                return(NotFound());
            }

            var shape = await _contentDisplay.BuildDisplayAsync(contentItem, this);

            return(View(shape));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Edit(string contentItemId)
        {
            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(NotFound());
            }

            var model = await _contentItemDisplayManager.BuildEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false);

            return(View(model));
        }
Exemplo n.º 16
0
        public async Task <ContentItem> GetParent(ContentItem current, VersionOptions options = null)
        {
            options ??= VersionOptions.Published;

            var containedPart = current?.As <ContainedPart>();

            if (containedPart == null)
            {
                return(null);
            }

            return(await _contentManager.GetAsync(containedPart.ListContentItemId, options));
        }
Exemplo n.º 17
0
        public async Task <ActionResult <IEnumerable <object> > > GetFolders(string contentitemid,
                                                                             string contentitemalias = "") //path
        {
//            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageOwnMedia))
//            {
//                return Unauthorized();
//            }


//            if (string.IsNullOrEmpty(contentitemid))
//            {
//                contentitemid = "";
//            }


            string actualcontentItemId = !string.IsNullOrEmpty(contentitemalias)
                ? await _contentAliasManager.GetContentItemIdAsync("alias:" + contentitemalias)
                : contentitemid;

            if (actualcontentItemId == null)
            {
                return(NotFound());
            }

            var contentItem = await _contentManager.GetAsync(actualcontentItemId);

            if (contentItem == null)
            {
                return(NotFound());
            }

            IEnumerable <ContentItem> queryResults = null;


            if (!String.IsNullOrEmpty(contentitemalias))
            {
                var realcontentItemId = await _contentAliasManager.GetContentItemIdAsync("alias:" + contentitemalias);

                queryResults = await _listContainerService.GetChildContentItems(realcontentItemId);
            }
            else if (!String.IsNullOrEmpty(contentitemid))
            {
                queryResults = await _listContainerService.GetChildContentItems(contentitemid);
            }

            var directoryItems = queryResults
                                 ?.Where(x => x.ContentType == "Folder" || x.ContentType == "MaterialLibraryFolder").ToList();


            return(directoryItems?.Select(CreateContentItemResult).ToArray());
        }
Exemplo n.º 18
0
        public async Task <ActionResult> OnGetAsync()
        {
            var contentItem = await _contentManager.GetAsync(Id);

            if (contentItem == null)
            {
                return(NotFound());
            }

            Title = contentItem.DisplayText ?? "Foo Title";
            Text  = contentItem.Content.TestContentPartA.Line;

            return(Page());
        }
        public async Task <ContentItem> Next(string currentContentItemId)
        {
            var currentContentItem = await _contentManager.GetAsync(currentContentItemId, VersionOptions.Latest);

            if (currentContentItem == null)
            {
                return(null);
            }
            return(await _iSession.Query <ContentItem, ContentItemIndex>(x => x.Published)
                   .Where(x => x.CreatedUtc > currentContentItem.CreatedUtc)
                   // .Where(x => x.ContentItemId == current.ContentItemId && x.CreatedUtc >= current.CreatedUtc)
                   // .Where(x => x.CreatedUtc > current.CreatedUtc)
                   .OrderBy(cr => cr.CreatedUtc).Take(1).FirstOrDefaultAsync());
        }
 public override IDisplayResult Display(ContentPickerField field, BuildFieldDisplayContext context)
 {
     return(Initialize <DisplayContentPickerFieldViewModel>(GetDisplayShapeType(context), async model =>
     {
         model.Field = field;
         model.Part = context.ContentPart;
         model.PartFieldDefinition = context.PartFieldDefinition;
         model.Updater = context.Updater;
         model.SelectedContentItemIds = string.Join(",", field.ContentItemIds);
         model.ContentItems = await _contentManager.GetAsync(field.ContentItemIds);
     })
            .Location("Content")
            .Location("SummaryAdmin", ""));
 }
Exemplo n.º 21
0
        public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, LiquidTemplateContext ctx)
        {
            if (input.Type == FluidValues.Array)
            {
                // List of content item ids
                var contentItemIds = input.Enumerate(ctx).Select(x => x.ToStringValue()).ToArray();

                return(FluidValue.Create(await _contentManager.GetAsync(contentItemIds), ctx.Options));
            }
            else
            {
                var contentItemId = input.ToStringValue();

                return(FluidValue.Create(await _contentManager.GetAsync(contentItemId), ctx.Options));
            }
        }
        public async ValueTask <IActionResult> EditPost(EditContentViewModel model)
        {
            if (string.IsNullOrEmpty(model.TargetId))
            {
                return(NotFound());
            }
            var contentItem = await _session.Query <ContentItem>()
                              .With <ContentItemIndex>(x => x.ContentItemId == model.TargetId &&
                                                       x.Owner == User.Identity.Name &&
                                                       x.Latest &&
                                                       x.ContentType == PublishContent)
                              .FirstOrDefaultAsync();

            if (contentItem == null)
            {
                return(NotFound());
            }
            contentItem = await _contentManager.GetAsync(model.TargetId, VersionOptions.DraftRequired);

            var shape = await _contentItemDisplayManager.UpdateEditorAsync(contentItem, _updateModelAccessor.ModelUpdater, false);

            if (!ModelState.IsValid)
            {
                await _session.CancelAsync();

                return(View("Edit", model));
            }
            await _contentManager.PublishAsync(contentItem);

            _notifier.Success(H["发布成功"]);
            return(RedirectToAction("index"));
        }
        public override IDisplayResult Edit(ContentPickerField field, BuildFieldEditorContext context)
        {
            return(Initialize <EditContentPickerFieldViewModel>(GetEditorShapeType(context), async model =>
            {
                model.ContentItemIds = string.Join(",", field.ContentItemIds);

                model.Field = field;
                model.Part = context.ContentPart;
                model.PartFieldDefinition = context.PartFieldDefinition;

                model.SelectedItems = new List <ContentPickerItemViewModel>();

                foreach (var contentItemId in field.ContentItemIds)
                {
                    var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Latest);

                    if (contentItem == null)
                    {
                        continue;
                    }

                    model.SelectedItems.Add(new ContentPickerItemViewModel
                    {
                        ContentItemId = contentItemId,
                        DisplayText = contentItem.ToString(),
                        HasPublished = await _contentManager.HasPublishedVersionAsync(contentItem)
                    });
                }
            }));
        }
        public async Task <IActionResult> Get(string contentItemId)
        {
            var contentItem = await _contentManager.GetAsync(contentItemId);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ViewContent, contentItem))
            {
                return(Unauthorized());
            }

            return(Ok(contentItem));
        }
        public async Task <IActionResult> Submit(string formId)
        {
            var form = await _contentManager.GetAsync(formId, VersionOptions.Published);

            if (form == null)
            {
                return(NotFound());
            }

            var formPart = form.As <VueForm>();

            // Verify if the form is enabled
            if (!formPart.Enabled.Value)
            {
                return(NotFound());
            }

            // form validation server side script
            var errorsDictionary  = new Dictionary <string, List <string> >();
            var scriptingProvider = new VueFormMethodsProvider(form, errorsDictionary);

            var script = form.As <VueFormScripts>();

            if (!string.IsNullOrEmpty(script?.OnValidation?.Text))
            {
                _scriptingManager.EvaluateJs(script.OnValidation.Text, scriptingProvider);
            }

            if (errorsDictionary.Count > 0)
            {
                return(Json(new { validationError = true, errors = errorsDictionary }));
            }

            if (!string.IsNullOrEmpty(script?.OnSubmitted?.Text))
            {
                _scriptingManager.EvaluateJs(script.OnSubmitted.Text, scriptingProvider);
            }

            // _workflow manager is null if workflow feature is not enabled
            if (_workflowManager != null)
            {
                //todo: make sure this does not create issues if the workflows has a blocking event
                await _workflowManager.TriggerEventAsync(nameof(VueFormSubmittedEvent),
                                                         input : new { VueForm = form },
                                                         correlationId : form.ContentItemId
                                                         );
            }

            // 302 are equivalent to 301 in this case. No permanent redirect
            if (HttpContext.Response.StatusCode == 301 || HttpContext.Response.StatusCode == 302)
            {
                var returnValue = new { redirect = WebUtility.UrlDecode(HttpContext.Response.Headers["Location"]) };
                HttpContext.Response.Clear();
                return(Json(returnValue));
            }
            var formSuccessMessage = await _liquidTemplateManager.RenderAsync(formPart.SuccessMessage?.Text, _htmlEncoder);

            // everything worked fine. send the success signal to the client
            return(Json(new { success = true, successMessage = formSuccessMessage }));
        }
Exemplo n.º 26
0
        public async Task <IActionResult> ListBinderTemplates()
        {
            string alias = "binder-templates";

            string contentItemId = alias != null
                ? await _contentAliasManager.GetContentItemIdAsync("alias:" + alias)
                : "NotFound";

            if (contentItemId == "NotFound")
            {
                return(NotFound());
            }

            var contentItem = await _contentManager.GetAsync(contentItemId, VersionOptions.Latest);

            if (contentItem == null)
            {
                return(NotFound());
            }

            if (!await _authorizationService.AuthorizeAsync(User, OrchardCore.Contents.Permissions.ViewContent,
                                                            contentItem))
            {
                return(Unauthorized());
            }

            var model = await _contentItemDisplayManager.BuildDisplayAsync(contentItem, this, "DetailAdmin");

            return(View("DisplayByAlias", model));
        }
Exemplo n.º 27
0
        public override IDisplayResult Edit(LocalizationSetContentPickerField field, BuildFieldEditorContext context)
        {
            return(Initialize <EditLocalizationSetContentPickerFieldViewModel>(GetEditorShapeType(context), async model =>
            {
                model.LocalizationSets = string.Join(",", field.LocalizationSets);

                model.Field = field;
                model.Part = context.ContentPart;
                model.PartFieldDefinition = context.PartFieldDefinition;

                model.SelectedItems = new List <VueMultiselectItemViewModel>();

                foreach (var kvp in await _contentLocalizationManager.GetFirstItemIdForSetsAsync(field.LocalizationSets))
                {
                    var contentItem = await _contentManager.GetAsync(kvp.Value, VersionOptions.Latest);

                    if (contentItem == null)
                    {
                        continue;
                    }

                    model.SelectedItems.Add(new VueMultiselectItemViewModel
                    {
                        Id = kvp.Key, //localization set
                        DisplayText = contentItem.ToString(),
                        HasPublished = await _contentManager.HasPublishedVersionAsync(contentItem)
                    });
                }
            }));
        }
Exemplo n.º 28
0
        private async Task <object> UpdateMediaToContentItemFolder(string contentItemId)
        {
            try
            {
                var fileToUpload = GetFileToUpload(null);
                var contentItem  = await _contentManager.GetAsync((contentItemId));


                return(await _attachedMediaToContentItemService.UploadToContentItemsFolderAsync(fileToUpload, contentItem));
            }
            catch (Exception e)
            {
                return(Json(e));
                // updater.ModelState.AddModelError(Prefix, S["{0}: There was an error handling the files.", context.PartFieldDefinition.DisplayName()]);
            }
        }
Exemplo n.º 29
0
 private async Task AssignGroupToProfiles(string[] contentItemIds, string groupContentItemId)
 {
     foreach (var contentItemId in contentItemIds)
     {
         await _profileGroupsService.AssignGroupAsync(await _contentManager.GetAsync(contentItemId), groupContentItemId);
     }
 }
Exemplo n.º 30
0
        public async Task UpdateContentItemOrdersAsync(IEnumerable <ContentItem> contentItems, int orderOfFirstItem)
        {
            var i = 0;

            foreach (var contentItem in contentItems)
            {
                var containedPart = contentItem.As <ContainedPart>();
                if (containedPart != null && containedPart.Order != orderOfFirstItem + i)
                {
                    containedPart.Order = orderOfFirstItem + i;
                    containedPart.Apply();

                    // Keep the published and draft orders the same to avoid confusion in the admin list.
                    if (!contentItem.IsPublished())
                    {
                        var publishedItem = await _contentManager.GetAsync(contentItem.ContentItemId, VersionOptions.Published);

                        if (publishedItem != null)
                        {
                            publishedItem.Alter <ContainedPart>(x => x.Order = orderOfFirstItem + i);
                            await _contentManager.UpdateAsync(publishedItem);
                        }
                    }

                    await _contentManager.UpdateAsync(contentItem);
                }

                i++;
            }
        }