public async Task <ContentItem> AssignGroupAsync(ContentItem profile, string groupContentItemId)
        {
            if (profile == null)
            {
                return(null);
            }

            using (var scope = await _shellHost.GetScopeAsync(_shellSettings))
            {
                var contentManager = scope.ServiceProvider.GetRequiredService <IContentManager>();

                profile.Alter <ProfileGroupedPart>(x => x.GroupContentItemId = groupContentItemId);

                profile.Apply(nameof(ProfileGroupedPart), profile.As <ProfileGroupedPart>());
                ContentExtensions.Apply(profile, profile);

                await contentManager.UpdateAsync(profile);

                await contentManager.PublishAsync(profile);

                await _session.CommitAsync();

                return(profile);
            }
        }
        public async Task UpdateUserIdentifier(ContentItem contentItem, IUser user)
        {
            var profilePart = contentItem.Get <ProfilePart>("ProfilePart");

            profilePart.UserIdentifier = await _userManager.GetUserIdAsync(user);

            contentItem.Apply("ProfilePart", profilePart);

            ContentExtensions.Apply(contentItem, contentItem);

            await _contentManager.UpdateAsync(contentItem);
        }
        private static async Task <ContentItem> UpdateAsync(IContentManager contentManager, ContentItem contentItem, Posting posting)
        {
            if (contentItem.DisplayText == posting.Text && contentItem.ComparePostingPart(posting))
            {
                return(contentItem);
            }

            contentItem.DisplayText = posting.Text;
            contentItem.SetLeverPostingPart(posting);

            ContentExtensions.Apply(contentItem, contentItem);

            await contentManager.UpdateAsync(contentItem);

            return(contentItem);
        }
        private async Task <ContentItem> CreateAsync(IContentManager contentManager, Posting posting)
        {
            var contentItem = await contentManager.NewAsync(Constants.Lever.ContentType);

            contentItem.DisplayText = posting.Text;
            contentItem.SetLeverPostingPart(posting);

            var autoroutePart = contentItem.As <AutoroutePart>();

            autoroutePart.Path = $"{_slugService.Slugify(posting.Text)}/{posting.Id}";
            contentItem.Apply(nameof(AutoroutePart), autoroutePart);

            ContentExtensions.Apply(contentItem, contentItem);

            await contentManager.CreateAsync(contentItem);

            await contentManager.PublishAsync(contentItem);

            return(contentItem);
        }
Esempio n. 5
0
        public async Task <ContentItem> CreateAsync(IUser user)
        {
            using (var scope = await _shellHost.GetScopeAsync(_shellSettings))
            {
                var contentManager = scope.ServiceProvider.GetRequiredService <IContentManager>();
                var contentItem    = await contentManager.NewAsync(Constants.ContentTypeName);

                var profile = contentItem.As <ProfilePart>();
                profile.UserIdentifier = await _userManager.GetUserIdAsync(user);

                profile.Apply();

                contentItem.DisplayText = user.UserName;

                contentItem.Apply(nameof(ProfilePart), profile);
                ContentExtensions.Apply(contentItem, contentItem);

                await contentManager.CreateAsync(contentItem);

                await contentManager.PublishAsync(contentItem);

                return(contentItem);
            }
        }
        private async Task <bool> ImportRowAsync(ImportRedirectRow row)
        {
            if (!ValidateRow(row))
            {
                return(false);
            }

            var existing = await _session.Query <ContentItem>()
                           .With <RedirectPartIndex>(x => x.Url == row.FromUrl)
                           .ListAsync();

            ContentItem redirectItem = null;
            var         newItem      = false;

            if (existing.Any())
            {
                redirectItem = existing.FirstOrDefault(x => x.Published);
            }

            if (redirectItem == null)
            {
                redirectItem = await _contentManager.NewAsync(Constants.RedirectContentType);

                redirectItem.Owner      = _httpContextAccessor.HttpContext.User.Identity.Name;
                redirectItem.CreatedUtc = DateTime.UtcNow;
                newItem = true;
            }

            if (redirectItem == null)
            {
                return(false);
            }

            var redirectPart = redirectItem.Get <RedirectPart>(nameof(RedirectPart));

            if (redirectPart == null)
            {
                return(false);
            }

            redirectItem.Author      = _httpContextAccessor.HttpContext.User.Identity.Name;
            redirectItem.DisplayText = row.Title;
            redirectPart.FromUrl     = row.FromUrl?.Trim();
            redirectPart.ToUrl       = row.ToUrl?.Trim();
            redirectPart.IsPermanent = true;
            redirectPart.Apply();
            redirectItem.Apply(nameof(RedirectPart), redirectPart);
            ContentExtensions.Apply(redirectItem, redirectItem);

            if (newItem)
            {
                await _contentManager.CreateAsync(redirectItem);
            }
            else
            {
                await _contentManager.UpdateAsync(redirectItem);
            }

            await _contentManager.PublishAsync(redirectItem);

            return(true);
        }