Inheritance: OrchardCore.ContentManagement.Handlers.ContentContextBase
コード例 #1
0
        public override async Task CreatedAsync(CreateContentContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);

            if (contentTypeDefinition == null)
            {
                return;
            }

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                var partName  = typePartDefinition.PartDefinition.Name;
                var activator = _contentPartFactory.GetTypeActivator(partName);

                var part = context.ContentItem.Get(activator.Type, typePartDefinition.Name) as ContentPart;

                if (part != null)
                {
                    var partHandlers = _contentPartHandlerResolver.GetHandlers(partName);
                    await partHandlers.InvokeAsync((handler, context, part) => handler.CreatedAsync(context, part), context, part, _logger);

                    // TODO: This can be removed in a future release as the recommended way is to use ContentOptions.
                    // Iterate existing handler registrations as multiple handlers maybe not be registered with ContentOptions.
                    await _partHandlers.InvokeAsync((handler, context, part) => handler.CreatedAsync(context, part), context, part, _logger);
                }
            }
        }
コード例 #2
0
 void IContentPartHandler.Created(CreateContentContext context, ContentPart part)
 {
     if (part is TPart)
     {
         Created(context, (TPart)part);
     }
 }
コード例 #3
0
 async Task IContentPartHandler.CreatedAsync(CreateContentContext context, ContentPart part)
 {
     if (part is TPart)
     {
         await CreatedAsync(context, (TPart)part);
     }
 }
コード例 #4
0
        public override void Creating(CreateContentContext context)
        {
            var utcNow = _clock.UtcNow;

            if (!context.ContentItem.CreatedUtc.HasValue)
            {
                context.ContentItem.CreatedUtc = utcNow;
            }
            context.ContentItem.ModifiedUtc = utcNow;

            var httpContext = _httpContextAccessor.HttpContext;

            if (context.ContentItem.Owner == null && (httpContext?.User?.Identity?.IsAuthenticated ?? false))
            {
                context.ContentItem.Owner = httpContext.User.Identity.Name;
            }
        }
コード例 #5
0
        public override Task CreatingAsync(CreateContentContext context)
        {
            var utcNow = _clock.UtcNow;

            if (!context.ContentItem.CreatedUtc.HasValue)
            {
                context.ContentItem.CreatedUtc = utcNow;
            }

            context.ContentItem.ModifiedUtc = utcNow;

            var httpContext = _httpContextAccessor.HttpContext;

            if (context.ContentItem.Owner == null && (httpContext?.User?.Identity?.IsAuthenticated ?? false))
            {
                context.ContentItem.Owner = context.ContentItem.Author = httpContext.User.Identity.Name;
            }

            return(Task.CompletedTask);
        }
コード例 #6
0
        public override async Task CreatingAsync(CreateContentContext context)
        {
            var contentTypeDefinition = _contentDefinitionManager.GetTypeDefinition(context.ContentItem.ContentType);

            if (contentTypeDefinition == null)
            {
                return;
            }

            foreach (var typePartDefinition in contentTypeDefinition.Parts)
            {
                var partName  = typePartDefinition.PartDefinition.Name;
                var activator = _contentPartFactory.GetTypeActivator(partName);

                var part = context.ContentItem.Get(activator.Type, typePartDefinition.Name) as ContentPart;

                if (part != null)
                {
                    await _partHandlers.InvokeAsync((handler, context, part) => handler.CreatingAsync(context, part), context, part, Logger);
                }
            }
        }
コード例 #7
0
 public virtual Task CreatedAsync(CreateContentContext context, TPart instance) => Task.CompletedTask;
コード例 #8
0
 public virtual void Created(CreateContentContext context, TPart instance)
 {
 }
コード例 #9
0
 public virtual Task CreatedAsync(CreateContentContext context)
 {
     return(Task.CompletedTask);
 }
コード例 #10
0
 Task IContentPartHandler.CreatedAsync(CreateContentContext context, ContentPart part)
 {
     return(part is TPart tpart
         ? CreatedAsync(context, tpart)
         : Task.CompletedTask);
 }