public async Task <IActionResult> Index()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageLayers))
            {
                return(Unauthorized());
            }

            var layers = await _layerService.GetLayersAsync();

            var widgets = await _layerService.GetLayerWidgetsAsync(c => c.Latest == true);

            var model = new LayersIndexViewModel {
                Layers = layers.Layers
            };

            model.Zones = (await _siteService.GetSiteSettingsAsync()).As <LayerSettings>()?.Zones ?? Array.Empty <string>();

            model.Widgets = new Dictionary <string, List <dynamic> >();

            foreach (var widget in widgets.OrderBy(x => x.Position))
            {
                var            zone = widget.Zone;
                List <dynamic> list;
                if (!model.Widgets.TryGetValue(zone, out list))
                {
                    model.Widgets.Add(zone, list = new List <dynamic>());
                }

                list.Add(await _contentItemDisplayManager.BuildDisplayAsync(widget.ContentItem, this, "SummaryAdmin"));
            }

            return(View(model));
        }
        public async Task <IActionResult> Index(LayersIndexViewModel model)
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageLayers))
            {
                return(Unauthorized());
            }

            return(RedirectToAction("Index"));
        }
Exemple #3
0
        public async Task <IActionResult> Index()
        {
            if (!await _authorizationService.AuthorizeAsync(User, Permissions.ManageLayers))
            {
                return(Forbid());
            }

            var layers = await _layerService.GetLayersAsync();

            var widgets = await _layerService.GetLayerWidgetsMetadataAsync(c => c.Latest == true);

            var model = new LayersIndexViewModel {
                Layers = layers.Layers.ToList()
            };

            var siteSettings = await _siteService.GetSiteSettingsAsync();

            var contentDefinitions = _contentDefinitionManager.ListTypeDefinitions();

            model.Zones   = siteSettings.As <LayerSettings>().Zones ?? Array.Empty <string>();
            model.Widgets = new Dictionary <string, List <dynamic> >();

            foreach (var widget in widgets.OrderBy(x => x.Position))
            {
                var            zone = widget.Zone;
                List <dynamic> list;
                if (!model.Widgets.TryGetValue(zone, out list))
                {
                    model.Widgets.Add(zone, list = new List <dynamic>());
                }

                if (contentDefinitions.Any(c => c.Name == widget.ContentItem.ContentType))
                {
                    list.Add(await _contentItemDisplayManager.BuildDisplayAsync(widget.ContentItem, _updateModelAccessor.ModelUpdater, "SummaryAdmin"));
                }
                else
                {
                    _logger.LogWarning("The Widget content item with id {ContentItemId} has no matching {ContentType} content type definition.", widget.ContentItem.ContentItemId, widget.ContentItem.ContentType);
                    await _notifier.WarningAsync(H["The Widget content item with id {0} has no matching {1} content type definition.", widget.ContentItem.ContentItemId, widget.ContentItem.ContentType]);
                }
            }

            return(View(model));
        }