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)); }
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)); }