mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-07-15 23:22:26 +08:00
Fix for #127 - Delete the layer "Homapage" cause the site crash (Build 2667)
--HG-- branch : dev
This commit is contained in:
parent
81c77a1901
commit
00d7c970de
@ -44,6 +44,12 @@ namespace Orchard.Widgets.Controllers {
|
||||
layers.First() :
|
||||
layers.FirstOrDefault(layer => layer.Id == id);
|
||||
|
||||
if (currentLayer == null) {
|
||||
// Incorrect layer id passed
|
||||
Services.Notifier.Error(T("Layer not found: {1}", id));
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
currentLayerWidgets = _widgetsService.GetWidgets().Where(widgetPart => widgetPart.LayerPart.Id == currentLayer.Id);
|
||||
}
|
||||
else {
|
||||
@ -237,7 +243,7 @@ namespace Orchard.Widgets.Controllers {
|
||||
Services.Notifier.Error(T("Removing Layer failed: {0}", exception.Message));
|
||||
}
|
||||
|
||||
return RedirectToAction("Index", "Admin", new { id });
|
||||
return RedirectToAction("Index");
|
||||
}
|
||||
|
||||
public ActionResult EditWidget(int id) {
|
||||
|
@ -3,6 +3,7 @@ using System.Linq;
|
||||
using JetBrains.Annotations;
|
||||
using Orchard.ContentManagement;
|
||||
using Orchard.ContentManagement.Aspects;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Themes;
|
||||
using Orchard.Widgets.Models;
|
||||
|
||||
@ -78,11 +79,21 @@ namespace Orchard.Widgets.Services {
|
||||
}
|
||||
|
||||
public void DeleteLayer(int layerId) {
|
||||
// Delete widgets in the layer
|
||||
foreach (WidgetPart widgetPart in GetWidgets(layerId)) {
|
||||
DeleteWidget(widgetPart.Id);
|
||||
}
|
||||
|
||||
// Delete actual layer
|
||||
_contentManager.Remove(GetLayer(layerId).ContentItem);
|
||||
}
|
||||
|
||||
public WidgetPart GetWidget(int widgetId) {
|
||||
return GetWidgets().FirstOrDefault(widgetPart => widgetPart.Id == widgetId);
|
||||
return _contentManager
|
||||
.Query<WidgetPart, WidgetPartRecord>()
|
||||
.Where(widget => widget.Id == widgetId)
|
||||
.List()
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
public WidgetPart CreateWidget(int layerId, string widgetType, string title, string position, string zone) {
|
||||
|
Loading…
Reference in New Issue
Block a user