Exemple #1
0
 public WidgetContext(ControllerContext controllerContext, Widget pageWidget, TextWriter writer, string sourceUrl)
 {
     HttpContext = controllerContext.HttpContext;
     RouteData = controllerContext.RouteData;
     Instance = pageWidget;
     Writer = writer;
     SourceUrl = sourceUrl;
 }
Exemple #2
0
        public Widget Add(string pageId, string widgetTypeId, string newContentArea, int position)
        {
            var page = pageService.Load(pageId);

            var contentArea = page.ContentAreas.SingleOrDefault(c => c.Name == newContentArea);
            if (contentArea == null)
                throw new ApplicationException("The content area does not exist");

            // find the widget
            var widget = All().SingleOrDefault(w => w.GetType().GetHashCode().ToString() == widgetTypeId);
            if (widget == null)
                throw new ApplicationException("Widget type cannot be found");

            var instance = new Widget(Guid.NewGuid().ToString(), widget.GetType().AssemblyQualifiedName) {Contents = string.Empty};
            contentArea.Widgets.Insert(position, instance);
            session.SaveChanges();
            pageService.ClearOutputCacheDependency(HttpContext.Current);
            return instance;
        }
Exemple #3
0
 protected void FindWidget(Page page, string widgetId, out Widget widget, out ContentArea contentArea)
 {
     widget = null;
     contentArea = null;
     foreach (var area in page.ContentAreas)
     {
         foreach (var w in area.Widgets.Where(w => w.Id == widgetId))
         {
             contentArea = area;
             widget = w;
             break;
         }
     }
 }