示例#1
0
        public static string Import(string portalId, Models.LayoutTemplate template, Dictionary <string, string> widgetContent, Dictionary <string, string> idMap, string userId = null)
        {
            userId = string.IsNullOrEmpty(userId) ? Account.AuditId : userId;
            var existing = Portal.GetLayoutTemplate(portalId, template.LayoutName);

            template.PortalId = portalId;
            template.Roles    = Security.GetNewRoleIds(template.Roles, idMap);
            template.Id       = existing != null ? existing.Id : null;
            foreach (var widget in template.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
                    }
                }
            }
            return(Portal.Save(template));
        }
示例#2
0
        public static string Save(Models.LayoutTemplate template, string userId = null)
        {
            userId            = string.IsNullOrEmpty(userId) ? Account.AuditId : userId;
            template.PortalId = string.IsNullOrEmpty(template.PortalId) ? CurrentPortalId : template.PortalId;
            if (!IsDuplicate(template))
            {
                var prevTemplate = GetPageTemplateById(template.Id);
                if (prevTemplate != null)
                {
                    var missing = (from p in prevTemplate.Widgets
                                   where !(from w in template.Widgets select w.Id).Contains(p.Id)
                                   select p);
                    foreach (var widget in missing)
                    {
                        widget.RemoveContent();
                    }
                }

                Repository.Current.StoreResource("LayoutTemplate", null, template, userId);
                foreach (var widget in template.Widgets)
                {
                    //widget.TemplateId = Template.Id;    //is this a hack?
                    if (widget.ContentJson != null) //needed for initial update where we want to assign ContentIds and not json...   may cause issue with blanking out contentids by trying to blank out contentjson... TODO:
                    {
                        widget.SaveContentJson(widget.ContentJson);
                    }
                }
                //after contentIds assigned, need to save them!
                var res = Repository.Current.StoreResource("LayoutTemplate", null, template, userId);
                return(res.Id);
            }
            else
            {
                throw new Exception(string.Format(Localization.GetLocalization(LocalizationType.Exception, "DuplicateResource.Error", "{0} already exists.   Duplicates Not Allowed.", "Core"), "LayoutTemplate"));
            }
        }