Beispiel #1
0
        /// <summary>
        /// Generates all partial pages required then triggers rendering of
        /// the top level page and saves to the pages table
        /// </summary>
        public Page GeneratePage(PageGenerationModel page)
        {
            page.Controls = _controlFactory.BuildControls(page.ControlConfigs);
            GenerateChildPages(page.Controls);

            var razor = new StringBuilder();

            if (page.Page.PageType == PageType.Partial)
            {
                Model model = _modelRepository.GetModel(page.Page.ModelId.Value);
                razor.AppendLine($"@model {model.Namespace}.{model.Name}");
                NameModels(page.Controls, "Model");
            }

            foreach (IControl control in page.Controls)
            {
                razor.AppendLine(control.Render());
            }

            _pageRepository.SavePage(page.Page);

            View view = new View()
            {
                PageId = page.Page.PageId,
                Razor  = razor.ToString()
            };

            _pageRepository.SaveView(view);

            return(page.Page);
        }