mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2026-02-09 09:16:41 +08:00
Refining extension methods. Adding a streamlined content manager creation method.
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041639
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
using Orchard.Models;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class Blog : ContentPartForRecord<BlogRecord> {
|
||||
public class Blog : ContentPart<BlogRecord> {
|
||||
public string Name { get { return Record.Name; } }
|
||||
public string Slug { get { return Record.Slug; } }
|
||||
public bool Enabled { get { return Record.Enabled; } }
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Orchard.Models;
|
||||
|
||||
namespace Orchard.Blogs.Models {
|
||||
public class BlogPost : ContentPartForRecord<BlogPostRecord> {
|
||||
public class BlogPost : ContentPart<BlogPostRecord> {
|
||||
public string BlogSlug { get { return Record.Blog.Slug; } }
|
||||
public string Title { get { return Record.Title; } }
|
||||
public string Slug { get { return Record.Slug; } }
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Orchard.Blogs.Models {
|
||||
public class BlogPostProvider : ContentProvider {
|
||||
public BlogPostProvider(IRepository<BlogPostRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<BlogPost>("blogpost"));
|
||||
Filters.Add(new StorageFilterForRecord<BlogPostRecord>(repository));
|
||||
Filters.Add(new StorageFilter<BlogPostRecord>(repository));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ namespace Orchard.Blogs.Models {
|
||||
public class BlogProvider : ContentProvider {
|
||||
public BlogProvider(IRepository<BlogRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<Blog>("blog"));
|
||||
Filters.Add(new StorageFilterForRecord<BlogRecord>(repository));
|
||||
Filters.Add(new StorageFilter<BlogRecord>(repository));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,20 +20,17 @@ namespace Orchard.Blogs.Services {
|
||||
}
|
||||
|
||||
public IEnumerable<Blog> Get() {
|
||||
IEnumerable<BlogRecord> blogs =_repository.Fetch(br => br.Enabled, br => br.Asc(br2 => br2.Name));
|
||||
IEnumerable<BlogRecord> blogs = _repository.Fetch(br => br.Enabled, br => br.Asc(br2 => br2.Name));
|
||||
|
||||
return blogs.Select(br => _contentManager.Get(br.Id).As<Blog>());
|
||||
return blogs.Select(br => _contentManager.Get<Blog>(br.Id));
|
||||
}
|
||||
|
||||
public Blog CreateBlog(CreateBlogParams parameters) {
|
||||
BlogRecord record = new BlogRecord() {Name = parameters.Name, Slug = parameters.Slug, Enabled = parameters.Enabled};
|
||||
|
||||
//TODO: (erikpo) Need an extension method or something for this default behavior
|
||||
Blog blog = _contentManager.New<Blog>("blog");
|
||||
blog.Record = record;
|
||||
_contentManager.Create(blog);
|
||||
|
||||
return blog;
|
||||
return _contentManager.Create<Blog>("blog", init => {
|
||||
init.Record.Name = parameters.Name;
|
||||
init.Record.Slug = parameters.Slug;
|
||||
init.Record.Enabled = parameters.Enabled;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using Orchard.Models.Driver;
|
||||
using Orchard.Models.Records;
|
||||
|
||||
namespace Orchard.Comments.Models {
|
||||
public class CommentSettings : ContentPartForRecord<CommentSettingsRecord> {
|
||||
public class CommentSettings : ContentPart<CommentSettingsRecord> {
|
||||
}
|
||||
|
||||
public class CommentSettingsRecord : ContentPartRecord {
|
||||
@@ -19,7 +19,7 @@ namespace Orchard.Comments.Models {
|
||||
public class CommentSettingsProvider : ContentProvider {
|
||||
public CommentSettingsProvider(IRepository<CommentSettingsRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<CommentSettings>("site"));
|
||||
Filters.Add(new StorageFilterForRecord<CommentSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new StorageFilter<CommentSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new TemplateFilterForRecord<CommentSettingsRecord>("CommentSettings"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ using Orchard.Models.Records;
|
||||
using Orchard.UI.Models;
|
||||
|
||||
namespace Orchard.Media.Models {
|
||||
public class MediaSettings : ContentPartForRecord<MediaSettingsRecord> {
|
||||
public class MediaSettings : ContentPart<MediaSettingsRecord> {
|
||||
}
|
||||
|
||||
public class MediaSettingsRecord : ContentPartRecord {
|
||||
@@ -15,7 +15,7 @@ namespace Orchard.Media.Models {
|
||||
public class MediaSettingsProvider : ContentProvider {
|
||||
public MediaSettingsProvider(IRepository<MediaSettingsRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<MediaSettings>("site"));
|
||||
Filters.Add(new StorageFilterForRecord<MediaSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new StorageFilter<MediaSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
}
|
||||
|
||||
protected override void GetEditors(GetEditorsContext context) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
using Orchard.Security;
|
||||
|
||||
namespace Orchard.Users.Models {
|
||||
public sealed class User : ContentPartForRecord<UserRecord>, IUser {
|
||||
public sealed class User : ContentPart<UserRecord>, IUser {
|
||||
public int Id {
|
||||
get { return ContentItem.Id; }
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ namespace Orchard.Users.Models {
|
||||
public class UserProvider : ContentProvider {
|
||||
public UserProvider(IRepository<UserRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<User>("user"));
|
||||
Filters.Add(new StorageFilterForRecord<UserRecord>(repository));
|
||||
Filters.Add(new StorageFilter<UserRecord>(repository));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,16 +30,12 @@ namespace Orchard.Users.Services {
|
||||
|
||||
public IUser CreateUser(CreateUserParams createUserParams) {
|
||||
Logger.Information("CreateUser {0} {1}", createUserParams.Username, createUserParams.Email);
|
||||
var record = new UserRecord {
|
||||
UserName = createUserParams.Username,
|
||||
Email = createUserParams.Email
|
||||
};
|
||||
SetPassword(record, createUserParams.Password);
|
||||
|
||||
var user = _contentManager.New("user");
|
||||
user.As<User>().Record = record;
|
||||
_contentManager.Create(user);
|
||||
return user.As<IUser>();
|
||||
|
||||
return _contentManager.Create<User>("user", init => {
|
||||
init.Record.UserName = createUserParams.Username;
|
||||
init.Record.Email = createUserParams.Email;
|
||||
SetPassword(init.Record, createUserParams.Password);
|
||||
});
|
||||
}
|
||||
|
||||
public IUser GetUser(string username) {
|
||||
@@ -47,7 +43,7 @@ namespace Orchard.Users.Services {
|
||||
if (userRecord == null) {
|
||||
return null;
|
||||
}
|
||||
return _contentManager.Get(userRecord.Id).As<IUser>();
|
||||
return _contentManager.Get<IUser>(userRecord.Id);
|
||||
}
|
||||
|
||||
public IUser ValidateUser(string username, string password) {
|
||||
@@ -55,7 +51,7 @@ namespace Orchard.Users.Services {
|
||||
if (userRecord == null || ValidatePassword(userRecord, password) == false)
|
||||
return null;
|
||||
|
||||
return _contentManager.Get(userRecord.Id).As<IUser>();
|
||||
return _contentManager.Get<IUser>(userRecord.Id);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -45,11 +45,11 @@ namespace Orchard.Wikis.Controllers
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Create(PageCreateViewModel model) {
|
||||
var page = _contentManager.New<WikiPage>("wikipage");
|
||||
page.Record.Name = model.Name;
|
||||
page.As<CommonPart>().Container = CurrentSite.ContentItem;
|
||||
_contentManager.Create(page);
|
||||
return RedirectToAction("show", new {page.ContentItem.Id});
|
||||
var page = _contentManager.Create<WikiPage>("wikipage", item => {
|
||||
item.Record.Name = model.Name;
|
||||
item.As<CommonPart>().Container = CurrentSite.ContentItem;
|
||||
});
|
||||
return RedirectToAction("show", new { page.ContentItem.Id });
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ using System.Web.Routing;
|
||||
using Orchard.Models;
|
||||
|
||||
namespace Orchard.Wikis.Models {
|
||||
public class WikiPage : ContentPartForRecord<WikiPageRecord>, IContentDisplayInfo {
|
||||
public class WikiPage : ContentPart<WikiPageRecord>, IContentDisplayInfo {
|
||||
|
||||
string IContentDisplayInfo.DisplayText {
|
||||
get { return Record.Name; }
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace Orchard.Wikis.Models {
|
||||
Filters.Add(new ActivatingFilter<CommonPart>("wikipage"));
|
||||
Filters.Add(new ActivatingFilter<RoutablePart>("wikipage"));
|
||||
Filters.Add(new ActivatingFilter<BodyPart>("wikipage"));
|
||||
Filters.Add(new StorageFilterForRecord<WikiPageRecord>(wikiPageRepository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new StorageFilter<WikiPageRecord>(wikiPageRepository) { AutomaticallyCreateMissingRecord = true });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ namespace Orchard.Wikis.Models {
|
||||
|
||||
public class WikiSettingsProvider : ContentProvider {
|
||||
public WikiSettingsProvider(IRepository<WikiSettingsRecord> repository) {
|
||||
Filters.Add(new ActivatingFilter<ContentPartForRecord<WikiSettingsRecord>>("site"));
|
||||
Filters.Add(new StorageFilterForRecord<WikiSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new ActivatingFilter<ContentPart<WikiSettingsRecord>>("site"));
|
||||
Filters.Add(new StorageFilter<WikiSettingsRecord>(repository) { AutomaticallyCreateMissingRecord = true });
|
||||
Filters.Add(new TemplateFilterForRecord<WikiSettingsRecord>("WikiSettings"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user