mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-14 19:04:51 +08:00
Updating sandbox sample
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042288
This commit is contained in:
@@ -155,7 +155,10 @@ namespace Orchard.Tests.Models {
|
||||
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "three"; });
|
||||
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "four"; });
|
||||
_session.Flush();
|
||||
var twoOrFour = _manager.Query().Where<GammaRecord>(x => x.Frap == "one" || x.Frap == "four").List();
|
||||
|
||||
var twoOrFour = _manager.Query()
|
||||
.Where<GammaRecord>(x => x.Frap == "one" || x.Frap == "four")
|
||||
.List();
|
||||
|
||||
Assert.That(twoOrFour.Count(), Is.EqualTo(2));
|
||||
Assert.That(twoOrFour.Count(x => x.Has<Gamma>()), Is.EqualTo(2));
|
||||
|
@@ -9,10 +9,8 @@ using Orchard.DevTools.ViewModels;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Records;
|
||||
|
||||
namespace Orchard.DevTools.Controllers
|
||||
{
|
||||
public class ContentController : Controller
|
||||
{
|
||||
namespace Orchard.DevTools.Controllers {
|
||||
public class ContentController : Controller {
|
||||
private readonly IRepository<ContentItemRecord> _contentItemRepository;
|
||||
private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
|
||||
private readonly IContentManager _contentManager;
|
||||
@@ -28,15 +26,15 @@ namespace Orchard.DevTools.Controllers
|
||||
|
||||
public ActionResult Index() {
|
||||
return View(new ContentIndexViewModel {
|
||||
Items = _contentItemRepository.Table.ToList(),
|
||||
Items = _contentManager.Query().OrderBy<ContentItemRecord, int>(x => x.Id).List(),
|
||||
Types = _contentTypeRepository.Table.ToList()
|
||||
});
|
||||
}
|
||||
|
||||
public ActionResult Details(int id) {
|
||||
var model = new ContentDetailsViewModel {
|
||||
Item = _contentManager.Get(id)
|
||||
};
|
||||
Item = _contentManager.Get(id)
|
||||
};
|
||||
model.PartTypes = model.Item.ContentItem.Parts
|
||||
.Select(x => x.GetType())
|
||||
.SelectMany(x => AllTypes(x))
|
||||
@@ -49,11 +47,11 @@ namespace Orchard.DevTools.Controllers
|
||||
|
||||
static IEnumerable<Type> AllTypes(Type type) {
|
||||
var scan = type;
|
||||
while(scan != null && scan != typeof(Object) && scan != typeof(ContentPart)) {
|
||||
while (scan != null && scan != typeof(Object) && scan != typeof(ContentPart)) {
|
||||
yield return scan;
|
||||
scan = scan.BaseType;
|
||||
}
|
||||
foreach(var itf in type.GetInterfaces()) {
|
||||
foreach (var itf in type.GetInterfaces()) {
|
||||
yield return itf;
|
||||
}
|
||||
}
|
||||
|
@@ -9,6 +9,6 @@ using Orchard.Mvc.ViewModels;
|
||||
namespace Orchard.DevTools.ViewModels {
|
||||
public class ContentIndexViewModel : BaseViewModel {
|
||||
public IEnumerable<ContentTypeRecord> Types { get; set; }
|
||||
public IEnumerable<ContentItemRecord> Items { get; set; }
|
||||
public IEnumerable<ContentItem> Items { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -25,14 +25,16 @@
|
||||
<h3>Content Types</h3>
|
||||
<ul>
|
||||
<%foreach(var item in Model.Types.OrderBy(x=>x.Name)){%>
|
||||
<li><%=Html.Encode(item.Name) %></li>
|
||||
<li><%=Html.Encode(item.Name) %> </li>
|
||||
<%}%>
|
||||
</ul>
|
||||
|
||||
<h3>Content Items</h3>
|
||||
<ul>
|
||||
<%foreach(var item in Model.Items.OrderBy(x=>x.Id)){%>
|
||||
<li><%=Html.ActionLink(item.Id+": "+item.ContentType.Name, "details", "content", new{item.Id},new{}) %></li>
|
||||
<li><%=Html.ActionLink(item.Id+": "+item.ContentType, "details", "content", new{item.Id},new{}) %>
|
||||
<%=Html.ItemDisplayLink("view", item) %>
|
||||
<%=Html.ItemEditLink("edit", item) %></li>
|
||||
<%}%>
|
||||
</ul>
|
||||
|
||||
|
@@ -3,28 +3,35 @@ using System.Linq;
|
||||
using System.Web.Mvc;
|
||||
using Orchard.Core.Common.Models;
|
||||
using Orchard.Data;
|
||||
using Orchard.Localization;
|
||||
using Orchard.Models;
|
||||
using Orchard.Models.Driver;
|
||||
using Orchard.Sandbox.Models;
|
||||
using Orchard.Sandbox.ViewModels;
|
||||
using Orchard.Security;
|
||||
using Orchard.Settings;
|
||||
using Orchard.UI.Notify;
|
||||
|
||||
namespace Orchard.Sandbox.Controllers
|
||||
{
|
||||
namespace Orchard.Sandbox.Controllers {
|
||||
public class PageController : Controller, IUpdateModel {
|
||||
private readonly IRepository<SandboxPageRecord> _pageRepository;
|
||||
private readonly IContentManager _contentManager;
|
||||
private readonly INotifier _notifier;
|
||||
|
||||
public PageController(IRepository<SandboxPageRecord> pageRepository, IContentManager contentManager) {
|
||||
_pageRepository = pageRepository;
|
||||
public PageController(IContentManager contentManager, INotifier notifier) {
|
||||
_contentManager = contentManager;
|
||||
_notifier = notifier;
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
var pages = _pageRepository.Fetch(x => true, o => o.Asc(x => x.Name));
|
||||
public ISite CurrentSite { get; set; }
|
||||
public IUser CurrentUser { get; set; }
|
||||
public Localizer T { get; set; }
|
||||
|
||||
|
||||
public ActionResult Index() {
|
||||
var model = new PageIndexViewModel {
|
||||
Pages = pages.Select(x => _contentManager.Get<SandboxPage>(x.Id)).ToList()
|
||||
Pages = _contentManager.Query()
|
||||
.OrderBy<SandboxPageRecord, string>(x => x.Name)
|
||||
.List<SandboxPage>()
|
||||
};
|
||||
return View(model);
|
||||
}
|
||||
@@ -38,13 +45,24 @@ namespace Orchard.Sandbox.Controllers
|
||||
}
|
||||
|
||||
public ActionResult Create() {
|
||||
var settings = CurrentSite.Get<ContentPart<SandboxSettingsRecord>>();
|
||||
if (settings.Record.AllowAnonymousEdits == false && CurrentUser == null) {
|
||||
_notifier.Error(T("Anonymous users can not create pages"));
|
||||
return RedirectToAction("index");
|
||||
}
|
||||
|
||||
return View(new PageCreateViewModel());
|
||||
}
|
||||
|
||||
public ISite CurrentSite { get; set; }
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(PageCreateViewModel model) {
|
||||
var settings = CurrentSite.Get<ContentPart<SandboxSettingsRecord>>();
|
||||
if (settings.Record.AllowAnonymousEdits == false && CurrentUser == null) {
|
||||
_notifier.Error(T("Anonymous users can not create pages"));
|
||||
return RedirectToAction("index");
|
||||
}
|
||||
|
||||
var page = _contentManager.Create<SandboxPage>("sandboxpage", item => {
|
||||
item.Record.Name = model.Name;
|
||||
});
|
||||
@@ -53,15 +71,27 @@ namespace Orchard.Sandbox.Controllers
|
||||
|
||||
|
||||
public ActionResult Edit(int id) {
|
||||
var model = new PageEditViewModel {Page = _contentManager.Get<SandboxPage>(id)};
|
||||
model.Editors = _contentManager.GetEditors(model.Page.ContentItem);
|
||||
var settings = CurrentSite.Get<ContentPart<SandboxSettingsRecord>>();
|
||||
if (settings.Record.AllowAnonymousEdits == false && CurrentUser == null) {
|
||||
_notifier.Error(T("Anonymous users can not edit pages"));
|
||||
return RedirectToAction("show", new{id});
|
||||
}
|
||||
|
||||
var model = new PageEditViewModel { Page = _contentManager.Get<SandboxPage>(id) };
|
||||
model.Editors = _contentManager.GetEditors(model.Page);
|
||||
return View(model);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Edit(int id, FormCollection input) {
|
||||
var settings = CurrentSite.Get<ContentPart<SandboxSettingsRecord>>();
|
||||
if (settings.Record.AllowAnonymousEdits == false && CurrentUser == null) {
|
||||
_notifier.Error(T("Anonymous users can not edit pages"));
|
||||
return RedirectToAction("show", new { id });
|
||||
}
|
||||
|
||||
var model = new PageEditViewModel { Page = _contentManager.Get<SandboxPage>(id) };
|
||||
model.Editors = _contentManager.UpdateEditors(model.Page.ContentItem, this);
|
||||
model.Editors = _contentManager.UpdateEditors(model.Page, this);
|
||||
if (!TryUpdateModel(model, input.ToValueProvider()))
|
||||
return View(model);
|
||||
|
||||
|
@@ -2,10 +2,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Sandbox.Models;
|
||||
|
||||
namespace Orchard.Sandbox.ViewModels {
|
||||
public class PageCreateViewModel {
|
||||
public class PageCreateViewModel : BaseViewModel {
|
||||
public string Name { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Sandbox.Models;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Sandbox.ViewModels {
|
||||
public class PageEditViewModel {
|
||||
public class PageEditViewModel : BaseViewModel {
|
||||
public SandboxPage Page { get; set; }
|
||||
public IEnumerable<ModelTemplate> Editors { get; set; }
|
||||
}
|
||||
|
@@ -4,6 +4,6 @@ using Orchard.Sandbox.Models;
|
||||
|
||||
namespace Orchard.Sandbox.ViewModels {
|
||||
public class PageIndexViewModel : BaseViewModel {
|
||||
public IList<SandboxPage> Pages { get; set; }
|
||||
public IEnumerable<SandboxPage> Pages { get; set; }
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.Mvc.ViewModels;
|
||||
using Orchard.Sandbox.Models;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Sandbox.ViewModels {
|
||||
public class PageShowViewModel {
|
||||
public class PageShowViewModel : BaseViewModel {
|
||||
public SandboxPage Page { get; set; }
|
||||
public IEnumerable<ModelTemplate> Displays { get; set; }
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@
|
||||
<% Html.Include("Navigation"); %>
|
||||
</div>
|
||||
<div id="main">
|
||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||
<h3>
|
||||
Create Page</h3>
|
||||
<%using (Html.BeginForm()) { %>
|
||||
|
@@ -19,15 +19,16 @@
|
||||
<% Html.Include("Navigation"); %>
|
||||
</div>
|
||||
<div id="main">
|
||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||
<h3>
|
||||
Edit Page</h3>
|
||||
<%using (Html.BeginForm()) { %>
|
||||
<ul>
|
||||
<li>
|
||||
<%=Html.LabelFor(x => x.Page.Record.Name)%><%=Html.EditorFor(x => x.Page.Record.Name)%></li>
|
||||
<%foreach (var x in Model.Editors) { %>
|
||||
<%=Html.EditorFor(m=>x.Model, x.TemplateName, x.Prefix) %>
|
||||
<%} %>
|
||||
<%foreach (var x in Model.Editors) { %>
|
||||
<%=Html.EditorFor(m=>x.Model, x.TemplateName, x.Prefix) %>
|
||||
<%} %>
|
||||
<li>
|
||||
<input type="submit" name="submit" value="Save" /></li>
|
||||
</ul>
|
||||
|
@@ -1,43 +1,39 @@
|
||||
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<PageIndexViewModel>" %>
|
||||
<%@ Import Namespace="Orchard.Sandbox.ViewModels"%>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html"%>
|
||||
|
||||
<%@ Import Namespace="Orchard.Sandbox.ViewModels" %>
|
||||
<%@ Import Namespace="Orchard.Mvc.Html" %>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title>TwoColumns</title>
|
||||
<link href="<%=ResolveUrl("~/Content/Site2.css") %>" rel="stylesheet" type="text/css" />
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="header">
|
||||
<div id="innerheader">
|
||||
<% Html.Include("header"); %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="page">
|
||||
<div id="sideBar">
|
||||
<% Html.Include("Navigation"); %>
|
||||
</div>
|
||||
|
||||
<div id="main">
|
||||
<h3>Sandbox Pages</h3>
|
||||
<ul>
|
||||
<li><%=Html.ActionLink("Create new page", "create") %></li>
|
||||
<%foreach(var item in Model.Pages.OrderBy(x=>x.Record.Name)){%>
|
||||
<li><%=Html.ActionLink(item.Record.Name??"(no name)", "show", new { item.ContentItem.Id }, new{})%></li>
|
||||
<%}%>
|
||||
</ul>
|
||||
|
||||
</div>
|
||||
|
||||
<div id="footer">
|
||||
<% Html.Include("footer"); %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="header">
|
||||
<div id="innerheader">
|
||||
<% Html.Include("header"); %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="page">
|
||||
<div id="sideBar">
|
||||
<% Html.Include("Navigation"); %>
|
||||
</div>
|
||||
<div id="main">
|
||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||
<h3>
|
||||
Sandbox Pages</h3>
|
||||
<ul>
|
||||
<li>
|
||||
<%=Html.ActionLink("Create new page", "create") %></li>
|
||||
<%foreach (var item in Model.Pages.OrderBy(x => x.Record.Name)) {%>
|
||||
<li>
|
||||
<%=Html.ActionLink(item.Record.Name??"(no name)", "show", new { item.ContentItem.Id }, new{})%></li>
|
||||
<%}%>
|
||||
</ul>
|
||||
</div>
|
||||
<div id="footer">
|
||||
<% Html.Include("footer"); %>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
|
@@ -19,6 +19,7 @@
|
||||
<% Html.Include("Navigation"); %>
|
||||
</div>
|
||||
<div id="main">
|
||||
<% Html.RenderPartial("Messages", Model.Messages); %>
|
||||
<h3>
|
||||
<%=Html.Encode(Model.Page.Record.Name) %></h3>
|
||||
<div>
|
||||
|
@@ -12,6 +12,6 @@ string CssClassName(NotifyType type) {
|
||||
return "validation-summary-errors";
|
||||
}</script>
|
||||
|
||||
<% foreach (var item in Model) { %>
|
||||
<%if (Model != null){ foreach (var item in Model) { %>
|
||||
<div class="<%=CssClassName(item.Type) %> message"><%=Html.Encode(item.Message) %></div>
|
||||
<% } %>
|
||||
<% }} %>
|
||||
|
Reference in New Issue
Block a user