Ejemplo n.º 1
0
        public static string Import(string portalId, Models.PageTemplate pageTemplate, Dictionary <string, string> widgetContent, Dictionary <string, string> idMap, string userId = null)
        {
            userId = string.IsNullOrEmpty(userId) ? Account.AuditId : userId;
            var existing = Portal.GetPageTemplate(pageTemplate.Urls.Count > 0 ? pageTemplate.Urls[0] : "", portalId);   //todo:  by first url ok???

            pageTemplate.PortalId = portalId;
            pageTemplate.Roles    = Security.GetNewRoleIds(pageTemplate.Roles, idMap);
            pageTemplate.Id       = existing != null ? existing.Id : null;

            foreach (var widget in pageTemplate.Widgets)
            {
                widget.ManifestId = GetIdMap <Models.WidgetManifest>(widget.ManifestId, idMap);
                widget.Roles      = Security.GetNewRoleIds(widget.Roles, idMap);

                //todo: not creating/mapping new widget ids?
                if (widgetContent.ContainsKey(widget.Id))
                {
                    var contentProvider = widget.Manifest.GetContentProvider();
                    if (contentProvider != null)
                    {
                        widget.ContentIds = contentProvider.Import(portalId, widget.Id, widgetContent[widget.Id], idMap).Values.ToList(); //returns mapped dictionary of old id to new id... we just need to use the new ids
                    }
                }
            }
            Logging.Logger.DebugFormat("Importing page template {0}", pageTemplate.ToJson());
            return(Portal.Save(pageTemplate));
        }