Exemple #1
0
        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));
        }
Exemple #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));
        }
 public IActionResult PageZones(QueryContext context)
 {
     var page = Service.Get(context.PageID);
     var layout = _layoutService.Get(page.LayoutId);
     var viewModel = new LayoutZonesViewModel
     {
         Page = page,
         Layout = layout,
         PageID = context.PageID,
         LayoutID = layout.ID,
         Zones = _zoneService.GetZonesByPageId(context.PageID),
         Widgets = _widgetService.GetAllByPage(Service.Get(context.PageID)),
         LayoutHtml = layout.Html
     };
     return View(viewModel);
 }
        public IActionResult PageZones(QueryContext context)
        {
            ILayoutService         layoutService         = HttpContext.RequestServices.GetService <ILayoutService>();
            IWidgetBasePartService widgetBasePartService = HttpContext.RequestServices.GetService <IWidgetBasePartService>();
            IRuleService           ruleService           = HttpContext.RequestServices.GetService <IRuleService>();
            var page      = Service.Get(context.PageID);
            var layout    = layoutService.GetByPage(page);
            var viewModel = new LayoutZonesViewModel
            {
                Page       = page,
                Layout     = layout,
                PageID     = context.PageID,
                LayoutID   = layout.ID,
                Zones      = layout.Zones,
                Widgets    = widgetBasePartService.GetAllByPage(page),
                LayoutHtml = layout.Html
            };
            var rules = ruleService.GetMatchRule(new RuleWorkContext
            {
                Url       = Url.Content(page.Url),
                UserAgent = Request.Headers["User-Agent"]
            });

            if (rules.Any())
            {
                var ruleDic     = rules.ToDictionary(m => m.RuleID, m => m);
                var rulesID     = rules.Select(m => m.RuleID).ToArray();
                var ruleWidgets = widgetBasePartService.GetAllByRule(rulesID);
                ruleWidgets.Each(widget =>
                {
                    var availableZones = layout.Zones.Where(z => ruleDic[widget.RuleID.Value].ZoneNames.Contains(z.ZoneName));
                    foreach (var item in availableZones)
                    {
                        widget.SetZone(item.HeadingCode);
                    }
                });
                viewModel.Widgets = viewModel.Widgets.Concat(ruleWidgets);
            }


            return(View(viewModel));
        }
Exemple #5
0
        public IActionResult PageZones(QueryContext context)
        {
            ILayoutService         layoutService         = HttpContext.RequestServices.GetService <ILayoutService>();
            IWidgetBasePartService widgetBasePartService = HttpContext.RequestServices.GetService <IWidgetBasePartService>();
            IRuleService           ruleService           = HttpContext.RequestServices.GetService <IRuleService>();
            var page      = Service.Get(context.PageID);
            var layout    = layoutService.GetByPage(page);
            var viewModel = new LayoutZonesViewModel
            {
                Page       = page,
                Layout     = layout,
                PageID     = context.PageID,
                LayoutID   = layout.ID,
                Zones      = layout.Zones,
                Widgets    = widgetBasePartService.GetAllByPage(page),
                LayoutHtml = layout.Html
            };
            var rules = ruleService.GetMatchRule(new RuleWorkContext
            {
                Url       = Url.Content(page.Url),
                UserAgent = Request.Headers["User-Agent"]
            });

            if (rules.Any())
            {
                var rulesID     = rules.Select(m => m.RuleID).ToArray();
                var ruleWidgets = widgetBasePartService.GetAllByRule(rulesID);
                ruleWidgets.Each(widget =>
                {
                    var zone = layout.Zones.FirstOrDefault(z => z.ZoneName == rules.First(m => m.RuleID == widget.RuleID).ZoneName);
                    if (zone != null)
                    {
                        widget.ZoneID = zone.HeadingCode;
                    }
                });
                viewModel.Widgets = viewModel.Widgets.Concat(ruleWidgets);
            }


            return(View(viewModel));
        }