Adding strongly typed IContentQuery interfaces

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042412
This commit is contained in:
loudej
2009-11-27 04:55:05 +00:00
parent 0c0b49dfc9
commit 3c0f413e34
18 changed files with 195 additions and 85 deletions

View File

@@ -18,7 +18,7 @@ namespace Orchard.Blogs.Services {
public BlogPost Get(Blog blog, string slug) {
RoutableRecord record =
_routableRepository.Get(r => r.ContentItem.ContentType.Name == "blogpost" && r.Slug == slug);
_routableRepository.Get(r => r.ContentItemRecord.ContentType.Name == "blogpost" && r.Slug == slug);
BlogPost blogPost = record != null ? _contentManager.Get<BlogPost>(record.Id) : null;
return blogPost != null && blogPost.Record.Blog.Id == blog.ContentItem.Id ? blogPost : null;
@@ -27,7 +27,7 @@ namespace Orchard.Blogs.Services {
public IEnumerable<BlogPost> Get(Blog blog) {
//TODO: (erikpo) Figure out how to sort by published date
IEnumerable<RoutableRecord> records =
_routableRepository.Fetch(rr => rr.ContentItem.ContentType.Name == "blogpost"
_routableRepository.Fetch(rr => rr.ContentItemRecord.ContentType.Name == "blogpost"
/*, bpr => bpr.Asc(bpr2 => bpr2.Published.GetValueOrDefault(new DateTime(2099, 1, 1)))*/);
//TODO: (erikpo) Need to filter by blog in the line above instead of filtering here

View File

@@ -17,13 +17,13 @@ namespace Orchard.Blogs.Services {
}
public Blog Get(string slug) {
RoutableRecord record = _routableRepository.Get(r => r.ContentItem.ContentType.Name == "blog" && r.Slug == slug);
RoutableRecord record = _routableRepository.Get(r => r.ContentItemRecord.ContentType.Name == "blog" && r.Slug == slug);
return record != null ?_contentManager.Get<Blog>(record.Id) : null;
}
public IEnumerable<Blog> Get() {
IEnumerable<RoutableRecord> records = _routableRepository.Fetch(rr => rr.ContentItem.ContentType.Name == "blog", rr => rr.Asc(rr2 => rr2.Title));
IEnumerable<RoutableRecord> records = _routableRepository.Fetch(rr => rr.ContentItemRecord.ContentType.Name == "blog", rr => rr.Asc(rr2 => rr2.Title));
return records.Select(rr => _contentManager.Get<Blog>(rr.Id));
}

View File

@@ -26,7 +26,7 @@ namespace Orchard.DevTools.Controllers {
public ActionResult Index() {
return View(new ContentIndexViewModel {
Items = _contentManager.Query().OrderBy<ContentItemRecord, int>(x => x.Id).List(),
Items = _contentManager.Query().List(),
Types = _contentTypeRepository.Table.ToList()
});
}

View File

@@ -29,18 +29,19 @@ namespace Orchard.Sandbox.Controllers {
public ActionResult Index() {
var model = new PageIndexViewModel {
Pages = _contentManager.Query()
.OrderBy<SandboxPageRecord, string>(x => x.Name)
.List<SandboxPage>()
Pages = _contentManager.Query<SandboxPage, SandboxPageRecord>()
.OrderBy(x => x.Name)
.List()
};
return View(model);
}
public ActionResult Show(int id) {
var page = _contentManager.Get<SandboxPage>(id);
var model = new PageShowViewModel {
Page = _contentManager.Get<SandboxPage>(id)
Page = page,
Displays = _contentManager.GetDisplays(page)
};
model.Displays = _contentManager.GetDisplays(model.Page.ContentItem);
return View(model);
}
@@ -74,7 +75,7 @@ namespace Orchard.Sandbox.Controllers {
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});
return RedirectToAction("show", new { id });
}
var model = new PageEditViewModel { Page = _contentManager.Get<SandboxPage>(id) };

View File

@@ -37,9 +37,9 @@ namespace Orchard.Users.Controllers {
public ActionResult Index() {
var model = new UsersIndexViewModel();
var users = _contentManager.Query("user")
.Where<UserRecord>(x => x.UserName != null)
.List<User>();
var users = _contentManager.Query<User,UserRecord>("user")
.Where(x => x.UserName != null)
.List();
model.Rows = users.Select(x => new UsersIndexViewModel.Row {User = x}).ToList();