Ejemplo n.º 1
0
        public ActionResult Index(int?layerId)
        {
            ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme();

            if (currentTheme == null)
            {
                Services.Notifier.Error(T("To manage widgets you must have a theme enabled."));
                return(RedirectToAction("Index", "Admin", new { area = "Dashboard" }));
            }

            IEnumerable <LayerPart> layers = _widgetsService.GetLayers().ToList();

            if (!layers.Any())
            {
                Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site."));
                return(RedirectToAction("AddLayer"));
            }

            LayerPart currentLayer = layerId == null
                ? layers.FirstOrDefault()
                : layers.FirstOrDefault(layer => layer.Id == layerId);

            if (currentLayer == null && layerId != null)   // Incorrect layer id passed
            {
                Services.Notifier.Error(T("Layer not found: {0}", layerId));
                return(RedirectToAction("Index"));
            }

            IEnumerable <string> allZones           = _widgetsService.GetZones();
            IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme);

            string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
            string zonePreviewImage     = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;

            dynamic viewModel = Shape.ViewModel()
                                .CurrentTheme(currentTheme)
                                .CurrentLayer(currentLayer)
                                .Layers(layers)
                                .Widgets(_widgetsService.GetWidgets())
                                .Zones(currentThemesZones)
                                .OrphanZones(allZones.Except(currentThemesZones))
                                .OrphanWidgets(_widgetsService.GetOrphanedWidgets())
                                .ZonePreviewImage(zonePreviewImage);

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return(View((object)viewModel));
        }
Ejemplo n.º 2
0
        public ActionResult Index(int?layerId, string culture)
        {
            ExtensionDescriptor currentTheme = _siteThemeService.GetSiteTheme();

            if (currentTheme == null)
            {
                Services.Notifier.Error(T("To manage widgets you must have a theme enabled."));
                return(RedirectToAction("Index", "Admin", new { area = "Dashboard" }));
            }

            IEnumerable <LayerPart> layers = _widgetsService.GetLayers().OrderBy(x => x.Name).ToList();

            if (!layers.Any())
            {
                Services.Notifier.Error(T("There are no widget layers defined. A layer will need to be added in order to add widgets to any part of the site."));
                return(RedirectToAction("AddLayer"));
            }

            LayerPart currentLayer = layerId == null
                                     // look for the "Default" layer, or take the first if it doesn't exist
                ? layers.FirstOrDefault(x => x.Name == "Default") ?? layers.FirstOrDefault()
                : layers.FirstOrDefault(layer => layer.Id == layerId);

            if (currentLayer == null && layerId != null)   // Incorrect layer id passed
            {
                Services.Notifier.Error(T("Layer not found: {0}", layerId));
                return(RedirectToAction("Index"));
            }

            IEnumerable <string> allZones           = _widgetsService.GetZones();
            IEnumerable <string> currentThemesZones = _widgetsService.GetZones(currentTheme);

            string zonePreviewImagePath = string.Format("{0}/{1}/ThemeZonePreview.png", currentTheme.Location, currentTheme.Id);
            string zonePreviewImage     = _virtualPathProvider.FileExists(zonePreviewImagePath) ? zonePreviewImagePath : null;

            var widgets = _widgetsService.GetWidgets();

            if (!String.IsNullOrWhiteSpace(culture))
            {
                widgets = widgets.Where(x => {
                    if (x.Has <ILocalizableAspect>())
                    {
                        return(String.Equals(x.As <ILocalizableAspect>().Culture, culture, StringComparison.InvariantCultureIgnoreCase));
                    }

                    return(false);
                }).ToList();
            }

            var viewModel = Shape.ViewModel()
                            .CurrentTheme(currentTheme)
                            .CurrentLayer(currentLayer)
                            .CurrentCulture(culture)
                            .Layers(layers)
                            .Widgets(widgets)
                            .Zones(currentThemesZones)
                            .Cultures(_cultureManager.ListCultures())
                            .OrphanZones(allZones.Except(currentThemesZones))
                            .OrphanWidgets(_widgetsService.GetOrphanedWidgets())
                            .ZonePreviewImage(zonePreviewImage);

            return(View(viewModel));
        }