コード例 #1
0
ファイル: WidgetController.cs プロジェクト: skehya/cms
        public ActionResult Create(QueryContext context)
        {
            var template = _widgetTemplateService.Get(context.WidgetTemplateID);
            var widget   = template.ToWidget(HttpContext.RequestServices);

            widget.PageID   = context.PageID;
            widget.LayoutID = context.LayoutID;
            widget.ZoneID   = context.ZoneID;
            widget.FormView = template.FormView;
            if (widget.PageID.IsNotNullAndWhiteSpace())
            {
                widget.Position = _widgetService.GetAllByPage(_pageService.Get(context.PageID)).Count(m => m.ZoneID == context.ZoneID) + 1;
            }
            else if (context.LayoutID.IsNotNullAndWhiteSpace())
            {
                widget.Position = _widgetService.GetByLayoutId(context.LayoutID).Count(m => m.ZoneID == context.ZoneID) + 1;
            }
            SetDataSource(widget);
            ViewBag.WidgetTemplateName = template.Title;
            ViewBag.ReturnUrl          = context.ReturnUrl;
            if (template.FormView.IsNotNullAndWhiteSpace())
            {
                return(View(template.FormView, widget));
            }
            return(View(widget));
        }
コード例 #2
0
        public ActionResult Create(QueryContext context)
        {
            WidgetBase        widget           = null;
            IWidgetPartDriver widgetPartDriver = null;

            if (context.WidgetTemplateID.IsNotNullAndWhiteSpace())
            {
                var template = _widgetTemplateService.Get(context.WidgetTemplateID);
                widget = template.ToWidget(HttpContext.RequestServices);
            }
            else if (context.WidgetID.IsNotNullAndWhiteSpace())
            {
                var widgetBasePart = _widgetService.Get(context.WidgetID);
                widgetPartDriver  = _widgetActivator.Create(widgetBasePart);
                widget            = widgetPartDriver.GetWidget(widgetBasePart.ToWidgetBase());
                widget.IsTemplate = false;
                widget.IsSystem   = false;
                widget.Thumbnail  = null;
                widget.RuleID     = null;
            }
            if (widget == null)
            {
                return(BadRequest());
            }

            widget.PageID   = context.PageID;
            widget.LayoutID = context.LayoutID;
            widget.ZoneID   = context.ZoneID;
            widget.RuleID   = context.RuleID;
            if (widget.PageID.IsNotNullAndWhiteSpace())
            {
                widget.Position = _widgetService.GetAllByPage(_pageService.Get(context.PageID)).Count(m => m.ZoneID == context.ZoneID) + 1;
            }
            else if (context.LayoutID.IsNotNullAndWhiteSpace())
            {
                widget.Position = _widgetService.GetByLayoutId(context.LayoutID).Count(m => m.ZoneID == context.ZoneID) + 1;
            }
            SetDataSource(widget);
            ViewBag.ReturnUrl = context.ReturnUrl;
            if (widgetPartDriver != null)
            {
                widgetPartDriver.AddWidget(widget);
                return(RedirectToAction("Edit", new { ID = widget.ID, ReturnUrl = context.ReturnUrl }));
            }

            if (widget.FormView.IsNotNullAndWhiteSpace())
            {
                return(View(widget.FormView, widget));
            }

            return(View(widget));
        }
コード例 #3
0
        public IActionResult LayoutZones(string ID)
        {
            var layout    = Service.Get(ID);
            var viewModel = new LayoutZonesViewModel
            {
                Layout     = layout,
                LayoutID   = ID,
                Zones      = _zoneService.GetZonesByLayoutId(ID),
                Widgets    = _widgetService.GetByLayoutId(ID),
                LayoutHtml = layout.Html
            };

            return(View(viewModel));
        }