Ejemplo n.º 1
0
        public JsonResult <bool> SaveWidget(string templateId, string layoutName, CoreModels.Widget widget)
        {
            return(API.Execute <bool>(r =>
            {
                CoreServices.Security.VerifyActivityAuthorized("Content", "Administration");

                //Unfortnuately, we cannot just save content.  Widgets are persisted on the template and their properties (Css, Style, etc.) may have changed.  We need to re-save the template  //widget.Manifest.GetContentProvider().Save(widget.ContentJson);
                var pageTemplate = CoreServices.Portal.GetPageTemplateById(templateId);
                var layoutTemplate = CoreServices.Portal.GetLayoutTemplate(CoreServices.Portal.CurrentPortalId, layoutName);

                //a widget will live on either the page or template, never both.
                if (pageTemplate != null)
                {
                    if (ReplaceWidget(pageTemplate.Widgets, widget))
                    {
                        CoreServices.Portal.Save(pageTemplate);
                    }
                }

                if (layoutTemplate != null)
                {
                    if (ReplaceWidget(layoutTemplate.Widgets, widget))
                    {
                        CoreServices.Portal.Save(layoutTemplate);
                    }
                }
                r.Data = true;
            }));
        }
Ejemplo n.º 2
0
 //todo: shouldn't there be a nice LINQ statement to accomplish this?
 private bool ReplaceWidget(List <CoreModels.Widget> widgets, CoreModels.Widget widget)
 {
     for (var i = 0; i < widgets.Count; i++)
     {
         if (widgets[i].Id == widget.Id)
         {
             widgets[i] = widget;
             return(true);
         }
     }
     return(false);
 }