public static UrlRedirectRule CreateUrlRedirect(string fromVirtualPath, Media toMedia)
        {
            var currentLanuageId = FrameworkSettings.GetCurrentLanguage().ID;
            var urlRedirectList  = MediaDetailsMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.MediaType.Name == MediaTypeEnum.UrlRedirectRuleList.ToString() && i.HistoryVersionNumber == 0 && i.LanguageID == currentLanuageId);
            var mediaType        = MediaDetailsMapper.GetDataModel().MediaTypes.FirstOrDefault(i => i.Name == MediaTypeEnum.UrlRedirectRule.ToString());

            if (urlRedirectList != null && mediaType != null)
            {
                fromVirtualPath = fromVirtualPath.Replace("~", "");

                var urlRewrite = (UrlRedirectRule)MediaDetailsMapper.CreateObject(mediaType.ID, null, urlRedirectList.Media);
                urlRewrite.Is301Redirect         = true;
                urlRewrite.VirtualPathToRedirect = fromVirtualPath;
                urlRewrite.RedirectToUrl         = toMedia.PermaShortCodeLink;
                urlRewrite.LinkTitle             = urlRewrite.SectionTitle = urlRewrite.Title = urlRewrite.VirtualPathToRedirect + " -> " + urlRewrite.RedirectToUrl;
                urlRewrite.PublishDate           = DateTime.Now;

                var user = UsersMapper.GetAllByRoleEnum(RoleEnum.Administrator).FirstOrDefault(i => i.IsActive);

                if (user != null)
                {
                    urlRewrite.CreatedByUser = urlRewrite.LastUpdatedByUser = user;
                }

                return(urlRewrite);
            }

            return(null);
        }
Example #2
0
        protected void DeleteAllHistory_Click(object sender, EventArgs e)
        {
            try
            {
                IEnumerable <IMediaDetail> historyMediaDetails = new List <IMediaDetail>();

                if (DeleteSavedDrafts.Checked)
                {
                    historyMediaDetails = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber > 0);
                }
                else
                {
                    historyMediaDetails = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber > 0 && !i.IsDraft);
                }

                historyMediaDetails = historyMediaDetails.ToList();

                foreach (var item in historyMediaDetails)
                {
                    var returnObj = MediaDetailsMapper.DeletePermanently((MediaDetail)item);
                }

                //ClearAllCache_OnClick(sender, e);
            }
            catch (Exception ex)
            {
                ErrorHelper.LogException(ex);

                DisplayErrorMessage("Error Clearing All Cache", ErrorHelper.CreateError(ex));
            }
        }
Example #3
0
        protected void Page_Init(object sender, EventArgs e)
        {
            var items = new List <IMediaDetail>();

            items.AddRange(MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber == 0 && (i.PublishDate > DateTime.Now || i.ExpiryDate <= DateTime.Now))); //MediaDetailsMapper.FilterByIsHistoryStatus(MediaDetailsMapper.FilterByPublishedStatus(MediaDetailsMapper.GetAll(), false), false)

            MediaDetailsGrid.SetItems(items.Distinct());
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            var items = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => !i.IsHistory && !i.ShowInMenu); //MediaDetailsMapper.FilterByIsHistoryStatus(MediaDetailsMapper.FilterByShowInMenuStatus(MediaDetailsMapper.GetAll(), false), false);

            MediaDetailsGrid.SetItems(items);
        }
        private void BindRootMedia(Media rootMedia)
        {
            /*var cache = FileCacheHelper.GetGenerateNavCache();
             *
             * if (!cache.IsError)
             * {
             *  var cacheData = cache.GetRawData<string>();
             *
             *  if (cacheData != "")
             *  {
             *      return;
             *  }
             * }*/

            var items = new List <IMediaDetail>();

            if (!IsBreadCrumbMenu)
            {
                /*var itemsCacheKey = $"{rootMedia.ID}_Items";
                 * var itemsCacheData = (List<IMediaDetail>)ContextHelper.GetFromCache(itemsCacheKey);
                 *
                 * if (itemsCacheData != null)
                 * {
                 *  return;
                 * }
                 * else
                 * {*/
                /*var items = MediaDetailsMapper.GetDataModel().MediaDetails.AsNoTracking().Where(i => i.Media.ParentMediaID == rootMedia.ID && i.HistoryVersionNumber == 0 && i.LanguageID == currentLanguage.ID && !i.IsDeleted && i.PublishDate <= DateTime.Now && (i.ExpiryDate == null || i.ExpiryDate > DateTime.Now)).OrderBy(i => i.Media.OrderIndex); //rootMedia.ChildMedias.SelectMany(m => m.MediaDetails.Where(i => i.HistoryVersionNumber == 0 && (i.ShowInMenu || i.RenderInFooter) && !i.IsDeleted && i.PostPublishDate <= DateTime.Now && (i.PostExpiryDate == null || i.PostExpiryDate > DateTime.Now))).OrderBy(i => i.Media.OrderIndex);
                 * Bind(items);*/

                //var mediaDetail = BaseMapper.GetDataModel().MediaDetails.FirstOrDefault(i => i.MediaID == rootMedia.ID && i.LanguageID == BasePage.CurrentLanguage.ID);

                var mediaDetail = rootMedia.GetLiveMediaDetail();

                if (mediaDetail == null || mediaDetail.MediaType == null)
                {
                    return;
                }

                if (mediaDetail.MediaType.Name == MediaTypeEnum.RootPage.ToString())
                {
                    rootMedia = WebsitesMapper.GetWebsite().Media;
                }

                var children = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.ShowInMenu && i.Media.ParentMediaID == rootMedia.ID && i.HistoryVersionNumber == 0 && i.LanguageID == currentLanguage.ID && !i.IsDeleted && i.PublishDate <= DateTime.Now && (i.ExpiryDate == null || i.ExpiryDate > DateTime.Now)).OrderBy(i => i.Media.OrderIndex).ToList();     //rootMedia.ChildMedias.SelectMany(m => m.MediaDetails.Where(i => i.HistoryVersionNumber == 0 && (i.ShowInMenu || i.RenderInFooter) && !i.IsDeleted && i.PostPublishDate <= DateTime.Now && (i.PostExpiryDate == null || i.PostExpiryDate > DateTime.Now))).OrderBy(i => i.Media.OrderIndex);
                items.AddRange(children);
                //items = mediaDetail.ChildMediaDetails.Where(i=>i.ShowInMenu).ToList();

                if (!items.Any() && RenderParentNavIfNoChildren)
                {
                    items = mediaDetail.Media.ParentMedia.GetLiveMediaDetail(mediaDetail.Language).ChildMediaDetails.Where(i => i.ShowInMenu).ToList();
                }

                //ContextHelper.SaveToCache(itemsCacheKey, itemsCacheData);
                // }
            }
            else
            {
                items = MediaDetailsMapper.GetAllParentMediaDetails(this.BasePage.CurrentMediaDetail, this.BasePage.CurrentLanguage).ToList();
            }

            Bind(items);
        }
        protected void ItemsList_OnItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                HyperLink Link      = (HyperLink)e.Item.FindControl("Link");
                ListView  ChildList = (ListView)e.Item.FindControl("ChildList");

                IMediaDetail detail = (IMediaDetail)e.Item.DataItem;

                if (!displayProtectedSections && detail.IsProtected)
                {
                    if (BasePage.CurrentUser == null)
                    {
                        e.Item.Visible = false;
                    }
                }

                Link.Text = detail.LinkTitle;

                string virtualPath = detail.AutoCalculatedVirtualPath;

                if (detail.UseDirectLink)
                {
                    virtualPath = detail.DirectLink;
                }

                if (currentDepth == 1)
                {
                    if (Link.CssClass == "")
                    {
                        Link.CssClass = TopLevelAnchorClasses;
                    }
                    else
                    {
                        Link.CssClass = Link.CssClass + " " + TopLevelAnchorClasses;
                    }
                }
                else
                {
                    if (Link.CssClass == "")
                    {
                        Link.CssClass = SubAnchorClasses;
                    }
                    else
                    {
                        Link.CssClass = Link.CssClass + " " + SubAnchorClasses;
                    }
                }

                if (detail.OpenInNewWindow)
                {
                    Link.Target = "_blank";
                }

                if (!virtualPath.StartsWith("{") && !virtualPath.EndsWith("/"))
                {
                    if (!virtualPath.Contains("."))
                    {
                        virtualPath += "/";
                    }
                }

                var path = virtualPath;

                if (!virtualPath.StartsWith("{"))
                {
                    path = URIHelper.ConvertToAbsUrl(virtualPath);

                    if (path.Contains("#") && path.EndsWith("/"))
                    {
                        path = path.Remove(path.Length - 1);
                    }
                }

                if (detail.RedirectToFirstChild)
                {
                    path = detail.ChildMediaDetails.Where(i => i.ShowInMenu).ElementAt(0).AbsoluteUrl;
                }

                Link.NavigateUrl = path;

                if (IsBreadCrumbMenu)
                {
                    if (URIHelper.GetCurrentVirtualPath() == virtualPath)
                    {
                        Link.NavigateUrl = "javascript:void(0);";
                    }
                }

                HtmlContainerControl li = (HtmlContainerControl)e.Item.FindControl("li");

                if (li.Attributes["class"] == null)
                {
                    li.Attributes.Add("class", "index-" + e.Item.DataItemIndex.ToString());
                }

                if (virtualPath == currentVirtualPath || detail.VirtualPath == currentVirtualPath)
                {
                    li.Attributes["class"] += " current";
                }
                else if (currentVirtualPath.Contains(virtualPath) || currentVirtualPath.Contains(detail.VirtualPath))
                {
                    li.Attributes["class"] += " currentParent";

                    if ((rootMedia != null) && (detail.MediaID == rootMedia.ID))
                    {
                        li.Attributes["class"] += " rootParent";
                    }
                }

                li.Attributes["class"] += $" MediaID-{detail.MediaID}";

                if (li.Attributes["class"].EndsWith("-"))
                {
                    li.Attributes["class"] = li.Attributes["class"].Substring(0, li.Attributes["class"].Length - 1);
                }

                if (!string.IsNullOrEmpty(detail.CssClasses))
                {
                    li.Attributes["class"] += " " + detail.CssClasses;
                }

                if (!string.IsNullOrEmpty(SubLIClasses))
                {
                    li.Attributes["class"] += " " + SubLIClasses;
                }

                li.Attributes["class"] = li.Attributes["class"].Trim();

                IEnumerable <IMediaDetail> childItems = new List <IMediaDetail>();

                if ((rootMedia != null) && (detail.MediaID != rootMedia.ID))
                {
                    //childItems = new List<IMediaDetail>();
                    //childItems = detail.ChildMediaDetails.Where(i=>i.ShowInMenu);

                    //childItems = details.Media.ChildMedias.SelectMany(i => i.MediaDetails.Where(j => j.HistoryVersionNumber == 0 && !j.IsDeleted && j.PostPublishDate <= DateTime.Now && j.LanguageID == details.LanguageID));
                    //childItems = MediaDetailsMapper.FilterOutDeletedAndArchived(MediaDetailsMapper.GetAllChildMediaDetails(details.Media, details.Language));

                    if (!renderHiddenMediaTypes)
                    {
                        childItems = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.ShowInMenu && i.Media.ParentMediaID == detail.Media.ID && i.HistoryVersionNumber == 0 && i.LanguageID == detail.LanguageID && !i.IsDeleted && i.PublishDate <= DateTime.Now && (i.ExpiryDate == null || i.ExpiryDate > DateTime.Now)).OrderBy(i => i.Media.OrderIndex).ToList();
                    }
                    else
                    {
                        childItems = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.Media.ParentMediaID == detail.Media.ID && i.HistoryVersionNumber == 0 && i.LanguageID == detail.LanguageID && !i.IsDeleted && i.PublishDate <= DateTime.Now && (i.ExpiryDate == null || i.ExpiryDate > DateTime.Now)).OrderBy(i => i.Media.OrderIndex).ToList();
                    }
                }

                if (!detail.CssClasses.Contains("NoChildren") && childItems.Any())
                {
                    if ((currentDepth < renderDepth) || (renderDepth == -1))
                    {
                        //ChildList.LayoutTemplate = ItemsList.LayoutTemplate;
                        ChildList.ItemTemplate   = ItemsList.ItemTemplate;
                        ChildList.ItemDataBound += new EventHandler <ListViewItemEventArgs>(ItemsList_OnItemDataBound);
                        ChildList.LayoutCreated += new EventHandler(ItemsList_OnLayoutCreated);

                        if ((childItems != null) && (IsFooterMenu))
                        {
                            childItems = childItems.Where(i => i.RenderInFooter);
                        }
                        else if (childItems != null)
                        {
                            childItems = childItems.Where(i => i.ShowInMenu);
                        }

                        if (!displayProtectedSections)
                        {
                            var list = childItems.OrderBy(i => i.Media.OrderIndex).ToList();

                            if (list.Count > 0)
                            {
                                li.Attributes["class"] += " has-children";
                            }

                            if ((currentDepth > 0) && (RenderParentItemInChildNav))
                            {
                                /*var parentDetails = new List<IMediaDetail>();
                                 * detail.CssClasses = "NoChildren";
                                 * parentDetails.Add(detail);*/

                                list = list.ToList();
                                detail.CssClasses = "NoChildren";
                                ((List <IMediaDetail>)list).Insert(0, detail);

                                //list = list.Concat(parentDetails);
                            }

                            ChildList.DataSource = list;
                            ChildList.DataBind();
                        }

                        currentDepth = currentDepth - 1;
                    }
                }
            }
        }
        protected void Page_Init(object sender, EventArgs e)
        {
            var items = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.IsDeleted);  //MediaDetailsMapper.FilterByIsHistoryStatus(MediaDetailsMapper.FilterByDeletedStatus(MediaDetailsMapper.GetAll(), true), false);

            MediaDetailsGrid.SetItems(items);
        }
Example #8
0
 private void Bind()
 {
     RecentEditsList.DataSource = MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber == 0 && i.MediaType.ShowInSiteTree).OrderByDescending(i => i.DateLastModified).Take(20).ToList();
     RecentEditsList.DataBind();
 }
Example #9
0
 public new static IEnumerable <IMediaDetail> GetAll()
 {
     return(MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.Name == enumName)); //FilterByMediaType(MediaDetailsMapper.GetAll(), MediaTypeEnum.Page);
 }
 public static IEnumerable <IMediaDetail> GetAllActiveByParent(IMediaDetail parent)
 {
     return(MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber == 0 && !i.IsDeleted && i.PublishDate <= DateTime.Now && (i.ExpiryDate == null || i.ExpiryDate > DateTime.Now) && i.VirtualPath.StartsWith(parent.VirtualPath)));
 }
 public static IEnumerable <IMediaDetail> GetAllActive()
 {
     return(MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.HistoryVersionNumber == 0 && !i.IsDeleted && i.PublishDate <= DateTime.Now && (i.ExpiryDate == null || i.ExpiryDate > DateTime.Now)));
 }
 public new static IEnumerable <IMediaDetail> GetAll()
 {
     return(MediaDetailsMapper.GetDataModel().MediaDetails.Where(i => i.MediaType.Name == _mediaTypeEnum)); //return FilterByMediaType(MediaDetailsMapper.GetAll(), MediaTypeEnum.UrlRedirectRule);
 }