Updating sandbox sample

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042288
This commit is contained in:
loudej
2009-11-26 03:00:12 +00:00
parent aea8aff4d3
commit bcf60a04dd
14 changed files with 102 additions and 67 deletions

View File

@@ -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 = "three"; });
_manager.Create<Gamma>("gamma", init => { init.Record.Frap = "four"; }); _manager.Create<Gamma>("gamma", init => { init.Record.Frap = "four"; });
_session.Flush(); _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(), Is.EqualTo(2));
Assert.That(twoOrFour.Count(x => x.Has<Gamma>()), Is.EqualTo(2)); Assert.That(twoOrFour.Count(x => x.Has<Gamma>()), Is.EqualTo(2));

View File

@@ -9,10 +9,8 @@ using Orchard.DevTools.ViewModels;
using Orchard.Models; using Orchard.Models;
using Orchard.Models.Records; using Orchard.Models.Records;
namespace Orchard.DevTools.Controllers namespace Orchard.DevTools.Controllers {
{ public class ContentController : Controller {
public class ContentController : Controller
{
private readonly IRepository<ContentItemRecord> _contentItemRepository; private readonly IRepository<ContentItemRecord> _contentItemRepository;
private readonly IRepository<ContentTypeRecord> _contentTypeRepository; private readonly IRepository<ContentTypeRecord> _contentTypeRepository;
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
@@ -28,7 +26,7 @@ namespace Orchard.DevTools.Controllers
public ActionResult Index() { public ActionResult Index() {
return View(new ContentIndexViewModel { return View(new ContentIndexViewModel {
Items = _contentItemRepository.Table.ToList(), Items = _contentManager.Query().OrderBy<ContentItemRecord, int>(x => x.Id).List(),
Types = _contentTypeRepository.Table.ToList() Types = _contentTypeRepository.Table.ToList()
}); });
} }

View File

@@ -9,6 +9,6 @@ using Orchard.Mvc.ViewModels;
namespace Orchard.DevTools.ViewModels { namespace Orchard.DevTools.ViewModels {
public class ContentIndexViewModel : BaseViewModel { public class ContentIndexViewModel : BaseViewModel {
public IEnumerable<ContentTypeRecord> Types { get; set; } public IEnumerable<ContentTypeRecord> Types { get; set; }
public IEnumerable<ContentItemRecord> Items { get; set; } public IEnumerable<ContentItem> Items { get; set; }
} }
} }

View File

@@ -32,7 +32,9 @@
<h3>Content Items</h3> <h3>Content Items</h3>
<ul> <ul>
<%foreach(var item in Model.Items.OrderBy(x=>x.Id)){%> <%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> </ul>

View File

@@ -3,28 +3,35 @@ using System.Linq;
using System.Web.Mvc; using System.Web.Mvc;
using Orchard.Core.Common.Models; using Orchard.Core.Common.Models;
using Orchard.Data; using Orchard.Data;
using Orchard.Localization;
using Orchard.Models; using Orchard.Models;
using Orchard.Models.Driver; using Orchard.Models.Driver;
using Orchard.Sandbox.Models; using Orchard.Sandbox.Models;
using Orchard.Sandbox.ViewModels; using Orchard.Sandbox.ViewModels;
using Orchard.Security;
using Orchard.Settings; using Orchard.Settings;
using Orchard.UI.Notify;
namespace Orchard.Sandbox.Controllers namespace Orchard.Sandbox.Controllers {
{
public class PageController : Controller, IUpdateModel { public class PageController : Controller, IUpdateModel {
private readonly IRepository<SandboxPageRecord> _pageRepository;
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
private readonly INotifier _notifier;
public PageController(IRepository<SandboxPageRecord> pageRepository, IContentManager contentManager) { public PageController(IContentManager contentManager, INotifier notifier) {
_pageRepository = pageRepository;
_contentManager = contentManager; _contentManager = contentManager;
_notifier = notifier;
} }
public ActionResult Index() public ISite CurrentSite { get; set; }
{ public IUser CurrentUser { get; set; }
var pages = _pageRepository.Fetch(x => true, o => o.Asc(x => x.Name)); public Localizer T { get; set; }
public ActionResult Index() {
var model = new PageIndexViewModel { 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); return View(model);
} }
@@ -38,13 +45,24 @@ namespace Orchard.Sandbox.Controllers
} }
public ActionResult Create() { 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()); return View(new PageCreateViewModel());
} }
public ISite CurrentSite { get; set; }
[HttpPost] [HttpPost]
public ActionResult Create(PageCreateViewModel model) { 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 => { var page = _contentManager.Create<SandboxPage>("sandboxpage", item => {
item.Record.Name = model.Name; item.Record.Name = model.Name;
}); });
@@ -53,15 +71,27 @@ namespace Orchard.Sandbox.Controllers
public ActionResult Edit(int id) { public ActionResult Edit(int id) {
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) }; var model = new PageEditViewModel { Page = _contentManager.Get<SandboxPage>(id) };
model.Editors = _contentManager.GetEditors(model.Page.ContentItem); model.Editors = _contentManager.GetEditors(model.Page);
return View(model); return View(model);
} }
[HttpPost] [HttpPost]
public ActionResult Edit(int id, FormCollection input) { 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) }; 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())) if (!TryUpdateModel(model, input.ToValueProvider()))
return View(model); return View(model);

View File

@@ -2,10 +2,11 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using System.Web;
using Orchard.Mvc.ViewModels;
using Orchard.Sandbox.Models; using Orchard.Sandbox.Models;
namespace Orchard.Sandbox.ViewModels { namespace Orchard.Sandbox.ViewModels {
public class PageCreateViewModel { public class PageCreateViewModel : BaseViewModel {
public string Name { get; set; } public string Name { get; set; }
} }
} }

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.Mvc.ViewModels;
using Orchard.Sandbox.Models; using Orchard.Sandbox.Models;
using Orchard.UI.Models; using Orchard.UI.Models;
namespace Orchard.Sandbox.ViewModels { namespace Orchard.Sandbox.ViewModels {
public class PageEditViewModel { public class PageEditViewModel : BaseViewModel {
public SandboxPage Page { get; set; } public SandboxPage Page { get; set; }
public IEnumerable<ModelTemplate> Editors { get; set; } public IEnumerable<ModelTemplate> Editors { get; set; }
} }

View File

@@ -4,6 +4,6 @@ using Orchard.Sandbox.Models;
namespace Orchard.Sandbox.ViewModels { namespace Orchard.Sandbox.ViewModels {
public class PageIndexViewModel : BaseViewModel { public class PageIndexViewModel : BaseViewModel {
public IList<SandboxPage> Pages { get; set; } public IEnumerable<SandboxPage> Pages { get; set; }
} }
} }

View File

@@ -1,9 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using Orchard.Mvc.ViewModels;
using Orchard.Sandbox.Models; using Orchard.Sandbox.Models;
using Orchard.UI.Models; using Orchard.UI.Models;
namespace Orchard.Sandbox.ViewModels { namespace Orchard.Sandbox.ViewModels {
public class PageShowViewModel { public class PageShowViewModel : BaseViewModel {
public SandboxPage Page { get; set; } public SandboxPage Page { get; set; }
public IEnumerable<ModelTemplate> Displays { get; set; } public IEnumerable<ModelTemplate> Displays { get; set; }
} }

View File

@@ -19,6 +19,7 @@
<% Html.Include("Navigation"); %> <% Html.Include("Navigation"); %>
</div> </div>
<div id="main"> <div id="main">
<% Html.RenderPartial("Messages", Model.Messages); %>
<h3> <h3>
Create Page</h3> Create Page</h3>
<%using (Html.BeginForm()) { %> <%using (Html.BeginForm()) { %>

View File

@@ -19,6 +19,7 @@
<% Html.Include("Navigation"); %> <% Html.Include("Navigation"); %>
</div> </div>
<div id="main"> <div id="main">
<% Html.RenderPartial("Messages", Model.Messages); %>
<h3> <h3>
Edit Page</h3> Edit Page</h3>
<%using (Html.BeginForm()) { %> <%using (Html.BeginForm()) { %>

View File

@@ -1,43 +1,39 @@
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<PageIndexViewModel>" %> <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<PageIndexViewModel>" %>
<%@ Import Namespace="Orchard.Sandbox.ViewModels" %> <%@ Import Namespace="Orchard.Sandbox.ViewModels" %>
<%@ Import Namespace="Orchard.Mvc.Html" %> <%@ 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"> <!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"> <html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<title>TwoColumns</title> <title>TwoColumns</title>
<link href="<%=ResolveUrl("~/Content/Site2.css") %>" rel="stylesheet" type="text/css" /> <link href="<%=ResolveUrl("~/Content/Site2.css") %>" rel="stylesheet" type="text/css" />
</head> </head>
<body> <body>
<div id="header"> <div id="header">
<div id="innerheader"> <div id="innerheader">
<% Html.Include("header"); %> <% Html.Include("header"); %>
</div> </div>
</div> </div>
<div id="page"> <div id="page">
<div id="sideBar"> <div id="sideBar">
<% Html.Include("Navigation"); %> <% Html.Include("Navigation"); %>
</div> </div>
<div id="main"> <div id="main">
<h3>Sandbox Pages</h3> <% Html.RenderPartial("Messages", Model.Messages); %>
<h3>
Sandbox Pages</h3>
<ul> <ul>
<li><%=Html.ActionLink("Create new page", "create") %></li> <li>
<%=Html.ActionLink("Create new page", "create") %></li>
<%foreach (var item in Model.Pages.OrderBy(x => x.Record.Name)) {%> <%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> <li>
<%=Html.ActionLink(item.Record.Name??"(no name)", "show", new { item.ContentItem.Id }, new{})%></li>
<%}%> <%}%>
</ul> </ul>
</div> </div>
<div id="footer"> <div id="footer">
<% Html.Include("footer"); %> <% Html.Include("footer"); %>
</div> </div>
</div> </div>
</body> </body>
</html> </html>

View File

@@ -19,6 +19,7 @@
<% Html.Include("Navigation"); %> <% Html.Include("Navigation"); %>
</div> </div>
<div id="main"> <div id="main">
<% Html.RenderPartial("Messages", Model.Messages); %>
<h3> <h3>
<%=Html.Encode(Model.Page.Record.Name) %></h3> <%=Html.Encode(Model.Page.Record.Name) %></h3>
<div> <div>

View File

@@ -12,6 +12,6 @@ string CssClassName(NotifyType type) {
return "validation-summary-errors"; return "validation-summary-errors";
}</script> }</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> <div class="<%=CssClassName(item.Type) %> message"><%=Html.Encode(item.Message) %></div>
<% } %> <% }} %>