Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pubudu 30 posts 133 karma points
    Apr 30, 2019 @ 05:22
    pubudu
    0

    SaveAndPublishWithStatus(message)

    " Services.ContentService.SaveAndPublishWithStatus(message); " Why this code is not working Umbraco8?

  • Rabea 34 posts 186 karma points
    Apr 30, 2019 @ 05:53
    Rabea
    1

    I believe this method is not available in V8

  • pubudu 30 posts 133 karma points
    Apr 30, 2019 @ 06:02
    pubudu
    0

    No Another solution?

  • Corné Strijkert 63 posts 411 karma points
    Apr 30, 2019 @ 10:14
    Corné Strijkert
    1

    I think you have to inject the INotificationService interface in your ctor. In Umbraco 8 everything can be 'injected', so where v7 contains some hard binded things, in v8 things are more seperated, so I think you can inject the notifications service when you would like to use it.

    Try something like this:

    public class ContentServiceHelper
    {
        private readonly IContentService _contentService;
        private readonly IUmbracoContextAccessor _umbracoContextAccessor;
        private readonly INotificationService _notificationService;
    
        public ContentServiceHelper(IContentService contentService, IUmbracoContextAccessor umbracoContextAccessor, INotificationService notificationService)
        {
            _contentService = contentService;
            _umbracoContextAccessor = umbracoContextAccessor;
            _notificationService = notificationService;
        }
    
        public IContent CreateContent(string name)
        {
            var content = _contentService.CreateContent(name, -1, DocType.ModelTypeAlias);
    
            var result = _contentService.SaveAndPublish(content);
            if (result.Success)
            {
                IUser user = null;
                if (_umbracoContextAccessor.UmbracoContext != null)
                {
                    user = _umbracoContextAccessor.UmbracoContext.Security.CurrentUser;
                    if (user != null)
                    {
                        _notificationService.SendNotifications(
                            user,
                            new[] { content },
                            "action",
                            "actionName",
                            new Uri("/"),
                            x => "subject",
                            x => "body"
                    }
                }
            }
    
            return content;
        }
    }
    

    I don't have tried this code sample yet, but it maybe gives you a headstart. Also, have a look at the source code of Umbraco V8 at:

    https://github.com/umbraco/Umbraco-CMS/blob/61cc22dccf65e3e0077f5fb93c4e0aa447abe581/src/Umbraco.Web/Compose/NotificationsComponent.cs

Please Sign in or register to post replies

Write your reply to:

Draft