public IActionResult Create()
        {
            var viewModel = new TodoViewModel();

            viewModel.TodoId      = _idGenerator.GenerateUniqueId();
            viewModel.DisplayMode = "Edit";
            return(View("Edit", viewModel));
        }
        public async Task <ContentItem> LocalizeAsync(ContentItem content, string targetCulture)
        {
            var localizationPart = content.As <LocalizationPart>();
            var siteSettings     = await _siteService.GetSiteSettingsAsync();

            // not sure if this is redundant or not. The check is also done in the Admin controller
            if (!siteSettings.GetConfiguredCultures().Any(c => String.Equals(c, targetCulture, StringComparison.OrdinalIgnoreCase)))
            {
                throw new InvalidOperationException("Cannot localize an unsupported culture");
            }

            if (String.IsNullOrEmpty(localizationPart.LocalizationSet))
            {
                // If the source content item is not yet localized, define its defaults

                localizationPart.LocalizationSet = _iidGenerator.GenerateUniqueId();
                localizationPart.Culture         = await GetDefaultCultureNameAsync();

                _session.Save(content);
            }
            else
            {
                var existingContent = await GetContentItem(localizationPart.LocalizationSet, targetCulture);

                if (existingContent != null)
                {
                    // already localized
                    return(existingContent);
                }
            }

            // Cloning the content item
            var cloned = await _contentManager.CloneAsync(content);

            var clonedPart = cloned.As <LocalizationPart>();

            clonedPart.Culture         = targetCulture;
            clonedPart.LocalizationSet = localizationPart.LocalizationSet;
            clonedPart.Apply();

            var context = new LocalizationContentContext(content, localizationPart.LocalizationSet, targetCulture);

            await Handlers.InvokeAsync(async handler => await handler.LocalizingAsync(context), _logger);

            await ReversedHandlers.InvokeAsync(async handler => await handler.LocalizedAsync(context), _logger);

            _session.Save(cloned);
            return(cloned);
        }
Beispiel #3
0
        public async Task <ContentItem> LocalizeAsync(ContentItem content, string targetCulture)
        {
            var supportedCultures = await _localizationService.GetSupportedCulturesAsync();

            if (!supportedCultures.Any(c => String.Equals(c, targetCulture, StringComparison.OrdinalIgnoreCase)))
            {
                throw new InvalidOperationException("Cannot localize an unsupported culture");
            }

            var localizationPart = content.As <LocalizationPart>();

            if (String.IsNullOrEmpty(localizationPart.LocalizationSet))
            {
                // If the source content item is not yet localized, define its defaults
                localizationPart.LocalizationSet = _iidGenerator.GenerateUniqueId();
                localizationPart.Culture         = await _localizationService.GetDefaultCultureAsync();

                _session.Save(content);
            }
            else
            {
                var existingContent = await GetContentItemAsync(localizationPart.LocalizationSet, targetCulture);

                if (existingContent != null)
                {
                    // already localized
                    return(existingContent);
                }
            }

            // Cloning the content item
            var cloned = await _contentManager.CloneAsync(content);

            var clonedPart = cloned.As <LocalizationPart>();

            clonedPart.Culture         = targetCulture;
            clonedPart.LocalizationSet = localizationPart.LocalizationSet;
            clonedPart.Apply();

            var context = new LocalizationContentContext(cloned, content, localizationPart.LocalizationSet, targetCulture);

            await Handlers.InvokeAsync((handler, context) => handler.LocalizingAsync(context), context, _logger);

            await ReversedHandlers.InvokeAsync((handler, context) => handler.LocalizedAsync(context), context, _logger);

            _session.Save(cloned);
            return(cloned);
        }
        public async Task AddAuditTrailEventAsync <TAuditTrailEventProvider>(AuditTrailContext auditTrailContext)
            where TAuditTrailEventProvider : IAuditTrailEventProvider
        {
            var eventDescriptors = DescribeEvents(auditTrailContext.EventName, typeof(TAuditTrailEventProvider).FullName);

            foreach (var eventDescriptor in eventDescriptors)
            {
                if (!await IsEventEnabledAsync(eventDescriptor))
                {
                    return;
                }

                var auditTrailCreateContext = new AuditTrailCreateContext(
                    auditTrailContext.EventName,
                    auditTrailContext.UserName,
                    auditTrailContext.EventData,
                    auditTrailContext.EventFilterKey,
                    auditTrailContext.EventFilterData);

                _auditTrailEventHandlers.Invoke((handler, context)
                                                => handler.CreateAsync(context), auditTrailCreateContext, Logger);

                var auditTrailEvent = new AuditTrailEvent
                {
                    Id              = _iidGenerator.GenerateUniqueId(),
                    Category        = eventDescriptor.CategoryDescriptor.Category,
                    EventName       = auditTrailCreateContext.EventName,
                    FullEventName   = eventDescriptor.FullEventName,
                    UserName        = !string.IsNullOrEmpty(auditTrailCreateContext.UserName) ? auditTrailContext.UserName : T["[empty]"],
                    CreatedUtc      = auditTrailCreateContext.CreatedUtc ?? _clock.UtcNow,
                    Comment         = auditTrailCreateContext.Comment.NewlinesToHtml(),
                    EventFilterData = auditTrailCreateContext.EventFilterData,
                    EventFilterKey  = auditTrailCreateContext.EventFilterKey,
                    ClientIpAddress = string.IsNullOrEmpty(auditTrailCreateContext.ClientIpAddress) ?
                                      await GetClientAddressAsync() : auditTrailCreateContext.ClientIpAddress
                };

                eventDescriptor.BuildAuditTrailEvent(auditTrailEvent, auditTrailCreateContext.EventData);

                _session.Save(auditTrailEvent);
            }
        }