public ActionResult ChooseWidget(int layerId, string zone, string returnUrl)
        {
            if (!Services.Authorizer.Authorize(Permissions.ManageWidgets, T(NotAuthorizedManageWidgetsLabel)))
            {
                return(new HttpUnauthorizedResult());
            }

            if (string.IsNullOrWhiteSpace(zone))
            {
                Services.Notifier.Error(T("Need a zone specified for widget placement."));
                return(RedirectToAction("Index"));
            }

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

            if (layers.Count() == 0)
            {
                Services.Notifier.Error(T("Layer not found: {0}", layerId));
                return(RedirectToAction("Index"));
            }

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

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

            dynamic viewModel = Shape.ViewModel()
                                .CurrentLayer(currentLayer)
                                .Zone(zone)
                                .WidgetTypes(_widgetsService.GetWidgetTypes())
                                .ReturnUrl(returnUrl);

            // Casting to avoid invalid (under medium trust) reflection over the protected View method and force a static invocation.
            return(View((object)viewModel));
        }
        public ActionResult ChooseWidget(int layerId, string zone, string returnUrl)
        {
            if (!IsAuthorizedToManageWidgets())
            {
                return(new HttpUnauthorizedResult());
            }

            if (string.IsNullOrWhiteSpace(zone))
            {
                Services.Notifier.Error(T("Need a zone specified for widget placement."));
                return(RedirectToAction("Index"));
            }

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

            if (!layers.Any())
            {
                Services.Notifier.Error(T("Layer not found: {0}", layerId));
                return(RedirectToAction("Index"));
            }

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

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

            var viewModel = Shape.ViewModel()
                            .CurrentLayer(currentLayer)
                            .Zone(zone)
                            .WidgetTypes(_widgetsService.GetWidgetTypes())
                            .ReturnUrl(returnUrl);

            return(View(viewModel));
        }