Пример #1
0
        public ViewResult Service(Page epPage, Template epTemplate)
        {
            if (epPage == null || epPage.Id == null)
                throw new ApplicationException("page is not specified");

            if (epTemplate == null || epTemplate.Id == null)
                throw new ApplicationException("template is not specified");

            var adminJs = new ResourceCollection();
            adminJs.Load(Resources.Resources.jQuery);
            adminJs.Load(Url.RouteUrl("AdminPanel", new {pageId = epPage.Id}).ToLowerInvariant(), MatchMode.Path,
                      "text/javascript");

            ViewBag.ContentAreas = epPage.ContentAreas.ToList();
            ViewBag.Page = epPage;
            ViewBag.Template = epTemplate;
            ViewBag.Root = contentManager.Folder.RootFolder;
            ViewBag.Js = contentManager.Page.Js(epPage.Id);
            ViewBag.AdminJs = adminJs;
            ViewBag.Css = contentManager.Page.Css(epPage.Id);

            // add cache dependency so we can do sitewide clears on page change
            contentManager.Page.AddOutputCacheDependency(
                ((HttpApplication) HttpContext.GetService(typeof (HttpApplication))).Context);

            return View(Path.GetFileNameWithoutExtension(epTemplate.ViewPath));
        }
Пример #2
0
        public static PageForm ToViewModel(this Page page)
        {
            var result = new PageForm();

            result.Id          = page.Id;
            result.IsLive      = page.IsLive;
            result.TemplateID  = page.TemplateId;
            result.Title       = page.Title ?? string.Empty;
            result.Url         = page.Url ?? string.Empty;
            result.UrlEditable = page.Url != "/";
            result.IsInMenu    = page.IsInMenu;
            result.MenuOrder   = page.MenuOrder;
            return(result);
        }
Пример #3
0
        public static PageSearchForm ToSearchViewModel(this Page page, ITemplateService templateService)
        {
            var form = new PageSearchForm();

            form.Id          = page.Id;
            form.Description = page.Description ?? string.Empty;
            form.Keywords    = page.Keywords ?? string.Empty;
            form.Language    = page.Language ?? 1033;
            form.Charset     = page.Charset ?? "UTF-8";
            form.Author      = page.Author ?? string.Empty;
            form.Copyright   = page.Copyright ?? string.Empty;
            form.Robots      = page.Robots ?? string.Empty;

            form.Def = templateService.Load(page.TemplateId).ToSearchViewModel();
            return(form);
        }
Пример #4
0
        public static PageFacebookForm ToFacebookViewModel(this Page page, ITemplateService templateService)
        {
            var form = new PageFacebookForm();

            form.Id            = page.Id;
            form.Type          = page.OgType ?? string.Empty;
            form.Email         = page.OgEmail ?? string.Empty;
            form.Phone         = page.OgPhone ?? string.Empty;
            form.Image         = page.OgImage ?? string.Empty;
            form.StreetAddress = page.OgStreetAddress ?? string.Empty;
            form.Locality      = page.OgLocality ?? string.Empty;
            form.Region        = page.OgRegion ?? string.Empty;
            form.Country       = page.OgCountry ?? string.Empty;
            form.Postcode      = page.OgPostcode ?? string.Empty;
            form.Longitude     = page.OgLongitude;
            form.Latitude      = page.OgLatitude;

            form.Def = templateService.Load(page.TemplateId).ToFacebookViewModel();
            return(form);
        }
Пример #5
0
        protected void ChangeTemplate(Page page, string templateId)
        {
            var template = templateService.Load(templateId);

            page.TemplateId = template.Id;
            page.ContentAreas.Clear();
            ClearOutputCacheDependency(HttpContext.Current);
        }
Пример #6
0
 public void Hide(Page page)
 {
     page.IsHidden = true;
     session.SaveChanges();
 }
Пример #7
0
        public ContentArea CreateContentArea(Page page, string name)
        {
            if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");

            var contentArea = new ContentArea {Name = name};
            page.ContentAreas.Add(contentArea);
            session.SaveChanges();
            return contentArea;
        }
Пример #8
0
        public Page Create(string name, string title, string url, string folderId, bool isLive, string templateId, bool hidden)
        {
            if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name");

            var template = templateService.Load(templateId);
            var folder = folderService.FindFolder(folderId);

            if (folder == null)
                throw new ApplicationException("folder does not exist");

            var page = new Page
            {
                Name = name,
                Title = title,
                Url = url.NormalizeUrl(),
                IsLive = isLive,
                TemplateId = template.Id,
                // these should be configurable
                Priority = url == "/" ? 1 : 0.8,
                ChangeFrequency = url == "/" ? ChangeFrequency.Daily : ChangeFrequency.Monthly,
                AnalyticsKey = template.AnalyticsKey,
                Created = DateTime.UtcNow,
                IsHidden = hidden
            };

            session.Store(page);
            session.SaveChanges();

            // update folder with page id
            if (!hidden)
                folder.Pages.Add(new PageItem { Id = page.Id, Name = page.Name, Url = page.Url, IsHomePage = page.IsHomePage() });

            session.SaveChanges();

            ClearOutputCacheDependency(HttpContext.Current);
            return page;
        }
Пример #9
0
 protected void FindWidget(Page page, string widgetId, out Widget widget, out ContentArea contentArea)
 {
     widget = null;
     contentArea = null;
     foreach (var area in page.ContentAreas)
     {
         foreach (var w in area.Widgets.Where(w => w.Id == widgetId))
         {
             contentArea = area;
             widget = w;
             break;
         }
     }
 }