Exemplo n.º 1
0
        public ActionResult Edit(int id)
        {
            if (!_permissionService.Authorize("ManageCustomPages"))
            {
                return(AccessDeniedView());
            }

            if (id == 0)
            {
                throw new Exception("custom Page Id Missing");
            }

            var model      = new CustomPageModel();
            var custompage = _customPageService.GetCustomPageById(id);

            if (custompage != null)
            {
                model     = custompage.ToModel();
                model.Url = Url.RouteUrl("CustomPage", new { name = custompage.GetSystemName() }, "http");
                var templateModel = custompage.Template?.ToModel();

                if (custompage.Template != null)
                {
                    foreach (var dt in custompage.Template.Tokens)
                    {
                        var dtModel = dt.ToModel();
                        templateModel.dataTokens.Add(dtModel);
                    }
                    model.template = templateModel;
                }

                // Load Available Templates
                model.AvailableTemplates.Add(new SelectListItem {
                    Text = "-- Select Template --", Value = "0"
                });
                foreach (var t in _templateService.GetAllTemplates())
                {
                    model.AvailableTemplates.Add(new SelectListItem {
                        Text = t.Name, Value = t.Id.ToString()
                    });
                }

                if (model.TemplateId > 0)
                {
                    foreach (var item in model.AvailableTemplates.Where(ss => ss.Value == model.TemplateId.ToString()))
                    {
                        item.Selected = true;
                    }

                    model.AvailableTemplates.First().Selected = false;
                }
            }

            return(View(model));
        }
Exemplo n.º 2
0
        public ActionResult PageDetails(int id)
        {
            var page = _customPageService.GetCustomPageById(id);

            if (page == null)
            {
                return(null);
            }
            if (!page.IsActive)
            {
                return(null);
            }

            var model = new CustomPageModel();

            model = PreparePageModel(page);

            if (model == null)
            {
                return(RedirectToRoute("Root"));
            }

            //template
            var template = _templateService.GetTemplateById(model.TemplateId);

            if (template == null)
            {
                template = _templateService.GetAllTemplates(true).FirstOrDefault();
            }
            if (template == null)
            {
                throw new Exception("No default template could be loaded");
            }

            return(View(model));
        }