Esempio n. 1
0
        public object ToClientModel(object serverModel)
        {
            var linkItemServerModel = (LinkItem)serverModel;
            var frame           = _frameRepository.Load(linkItemServerModel.Target);
            var nullable        = frame != null ? frame.ID : new int?();
            var href            = linkItemServerModel.Href;
            var hrefWithoutHash = href;
            var anchorOnPage    = "";
            var indexOfHash     = href.IndexOf('#');

            if (indexOfHash > 0)
            {
                hrefWithoutHash = href.Substring(0, indexOfHash - 1);
                anchorOnPage    = href.Substring(indexOfHash + 1);
            }

            var clientModel = new ExtendedEPiLinkModel
            {
                Text           = linkItemServerModel.Text,
                Title          = linkItemServerModel.Title,
                Href           = hrefWithoutHash,
                AnchorOnPage   = anchorOnPage,
                Target         = nullable,
                TypeIdentifier = _typeIdentifier,
                Attributes     = linkItemServerModel.Attributes
            };

            ModifyIContentProperties(linkItemServerModel, clientModel);
            return(clientModel);
        }
Esempio n. 2
0
        private void ModifyIContentProperties(LinkItem serverModel, ExtendedEPiLinkModel clientModel)
        {
            var mappedHref = serverModel.GetMappedHref();

            if (string.IsNullOrEmpty(mappedHref))
            {
                return;
            }
            var hrefWithoutHash = mappedHref;
            var anchorOnPage    = "";
            var indexOfHash     = mappedHref.IndexOf('#');

            if (indexOfHash > 0)
            {
                hrefWithoutHash = mappedHref.Substring(0, indexOfHash - 1);
                anchorOnPage    = mappedHref.Substring(indexOfHash + 1);
            }

            clientModel.Href         = hrefWithoutHash;
            clientModel.AnchorOnPage = anchorOnPage;
            var      contentGuid      = PermanentLinkUtility.GetGuid(hrefWithoutHash);
            var      contentReference = PermanentLinkUtility.FindContentReference(contentGuid);
            IContent content;

            if (!(contentReference != ContentReference.EmptyReference) || !_contentRepository.TryGet(contentReference, out content))
            {
                return;
            }
            clientModel.TypeIdentifier = _uiDescriptors.GetTypeIdentifiers(content.GetType()).FirstOrDefault();
            var friendlyUrl           = _urlHelper.ContentUrl(content.ContentLink);
            var absoluteUriBySettings = UriSupport.AbsoluteUrlBySettings(friendlyUrl);

            clientModel.PublicUrl = indexOfHash > 0 ?
                                    string.Format("{0}#{1}", absoluteUriBySettings, anchorOnPage) :
                                    absoluteUriBySettings;
        }