mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 11:44:58 +08:00
Changing the IContentManager interface to favor ContentItem values instead of IContent
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4042075
This commit is contained in:
@@ -43,17 +43,17 @@ namespace Orchard.Tests.Packages.Users.Controllers {
|
|||||||
|
|
||||||
var manager = _container.Resolve<IContentManager>();
|
var manager = _container.Resolve<IContentManager>();
|
||||||
|
|
||||||
var userOne = manager.New("user").As<User>();
|
var userOne = manager.New<User>("user");
|
||||||
userOne.Record = new UserRecord { UserName = "one" };
|
userOne.Record = new UserRecord { UserName = "one" };
|
||||||
manager.Create(userOne);
|
manager.Create(userOne.ContentItem);
|
||||||
|
|
||||||
var userTwo = manager.New("user").As<User>();
|
var userTwo = manager.New<User>("user");
|
||||||
userTwo.Record = new UserRecord { UserName = "two" };
|
userTwo.Record = new UserRecord { UserName = "two" };
|
||||||
manager.Create(userTwo);
|
manager.Create(userTwo.ContentItem);
|
||||||
|
|
||||||
var userThree = manager.New("user").As<User>();
|
var userThree = manager.New<User>("user");
|
||||||
userThree.Record = new UserRecord { UserName = "three" };
|
userThree.Record = new UserRecord { UserName = "three" };
|
||||||
manager.Create(userThree);
|
manager.Create(userThree.ContentItem);
|
||||||
|
|
||||||
_controller = _container.Resolve<AdminController>();
|
_controller = _container.Resolve<AdminController>();
|
||||||
|
|
||||||
|
@@ -102,7 +102,7 @@ namespace Orchard.Tests.Models {
|
|||||||
public void GetByIdShouldDetermineTypeAndLoadParts() {
|
public void GetByIdShouldDetermineTypeAndLoadParts() {
|
||||||
var modelRecord = CreateModelRecord("alpha");
|
var modelRecord = CreateModelRecord("alpha");
|
||||||
|
|
||||||
var contentItem = _manager.Get(modelRecord.Id).ContentItem;
|
var contentItem = _manager.Get(modelRecord.Id);
|
||||||
Assert.That(contentItem.ContentType, Is.EqualTo("alpha"));
|
Assert.That(contentItem.ContentType, Is.EqualTo("alpha"));
|
||||||
Assert.That(contentItem.Id, Is.EqualTo(modelRecord.Id));
|
Assert.That(contentItem.Id, Is.EqualTo(modelRecord.Id));
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ namespace Orchard.Tests.Models {
|
|||||||
|
|
||||||
// create a gamma record
|
// create a gamma record
|
||||||
var gamma = new GammaRecord {
|
var gamma = new GammaRecord {
|
||||||
ContentItem = _container.Resolve<IRepository<ContentItemRecord>>().Get(model.ContentItem.Id),
|
ContentItem = _container.Resolve<IRepository<ContentItemRecord>>().Get(model.Id),
|
||||||
Frap = "foo"
|
Frap = "foo"
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -130,11 +130,11 @@ namespace Orchard.Tests.Models {
|
|||||||
// re-fetch from database
|
// re-fetch from database
|
||||||
model = _manager.Get(modelRecord.Id);
|
model = _manager.Get(modelRecord.Id);
|
||||||
|
|
||||||
Assert.That(model.ContentItem.ContentType, Is.EqualTo("gamma"));
|
Assert.That(model.ContentType, Is.EqualTo("gamma"));
|
||||||
Assert.That(model.ContentItem.Id, Is.EqualTo(modelRecord.Id));
|
Assert.That(model.Id, Is.EqualTo(modelRecord.Id));
|
||||||
Assert.That(model.Is<Gamma>(), Is.True);
|
Assert.That(model.Is<Gamma>(), Is.True);
|
||||||
Assert.That(model.As<Gamma>().Record, Is.Not.Null);
|
Assert.That(model.As<Gamma>().Record, Is.Not.Null);
|
||||||
Assert.That(model.As<Gamma>().Record.ContentItem.Id, Is.EqualTo(model.ContentItem.Id));
|
Assert.That(model.As<Gamma>().Record.ContentItem.Id, Is.EqualTo(model.Id));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,7 +143,7 @@ namespace Orchard.Tests.Models {
|
|||||||
var beta = _manager.New("beta");
|
var beta = _manager.New("beta");
|
||||||
_manager.Create(beta);
|
_manager.Create(beta);
|
||||||
|
|
||||||
var modelRecord = _container.Resolve<IRepository<ContentItemRecord>>().Get(beta.ContentItem.Id);
|
var modelRecord = _container.Resolve<IRepository<ContentItemRecord>>().Get(beta.Id);
|
||||||
Assert.That(modelRecord, Is.Not.Null);
|
Assert.That(modelRecord, Is.Not.Null);
|
||||||
Assert.That(modelRecord.ContentType.Name, Is.EqualTo("beta"));
|
Assert.That(modelRecord.ContentType.Name, Is.EqualTo("beta"));
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ namespace Orchard.Models {
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
initialize(content);
|
initialize(content);
|
||||||
manager.Create(content);
|
manager.Create(content.ContentItem);
|
||||||
return content;
|
return content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -31,7 +31,7 @@ namespace Orchard.Models {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IContent New(string contentType) {
|
public virtual ContentItem New(string contentType) {
|
||||||
|
|
||||||
// create a new kernel for the model instance
|
// create a new kernel for the model instance
|
||||||
var context = new ActivatingContentContext {
|
var context = new ActivatingContentContext {
|
||||||
@@ -55,29 +55,27 @@ namespace Orchard.Models {
|
|||||||
return context2.ContentItem;
|
return context2.ContentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IContent Get(int id) {
|
public virtual ContentItem Get(int id) {
|
||||||
// obtain root record to determine the model type
|
// obtain root record to determine the model type
|
||||||
var contentItemRecord = _contentItemRepository.Get(id);
|
var record = _contentItemRepository.Get(id);
|
||||||
|
|
||||||
// no record of that id means content item doesn't exist
|
// no record of that id means content item doesn't exist
|
||||||
if (contentItemRecord == null)
|
if (record == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
// allocate instance and set record property
|
// allocate instance and set record property
|
||||||
var content = New(contentItemRecord.ContentType.Name);
|
var contentItem = New(record.ContentType.Name);
|
||||||
content.ContentItem.Record = contentItemRecord;
|
contentItem.Id = record.Id;
|
||||||
|
contentItem.Record = record;
|
||||||
|
|
||||||
// create a context with a new instance to load
|
// create a context with a new instance to load
|
||||||
var context = new LoadContentContext {
|
var context = new LoadContentContext {
|
||||||
Id = contentItemRecord.Id,
|
Id = contentItem.Id,
|
||||||
ContentType = contentItemRecord.ContentType.Name,
|
ContentType = contentItem.ContentType,
|
||||||
ContentItemRecord = contentItemRecord,
|
ContentItemRecord = record,
|
||||||
ContentItem = content.ContentItem
|
ContentItem = contentItem,
|
||||||
};
|
};
|
||||||
|
|
||||||
// set the id
|
|
||||||
context.ContentItem.Id = context.Id;
|
|
||||||
|
|
||||||
// invoke drivers to acquire state, or at least establish lazy loading callbacks
|
// invoke drivers to acquire state, or at least establish lazy loading callbacks
|
||||||
foreach (var driver in Drivers) {
|
foreach (var driver in Drivers) {
|
||||||
driver.Loading(context);
|
driver.Loading(context);
|
||||||
@@ -89,18 +87,18 @@ namespace Orchard.Models {
|
|||||||
return context.ContentItem;
|
return context.ContentItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Create(IContent content) {
|
public void Create(ContentItem contentItem) {
|
||||||
// produce root record to determine the model id
|
// produce root record to determine the model id
|
||||||
var modelRecord = new ContentItemRecord { ContentType = AcquireContentTypeRecord(content.ContentItem.ContentType) };
|
var modelRecord = new ContentItemRecord { ContentType = AcquireContentTypeRecord(contentItem.ContentType) };
|
||||||
_contentItemRepository.Create(modelRecord);
|
_contentItemRepository.Create(modelRecord);
|
||||||
content.ContentItem.Record = modelRecord;
|
contentItem.Record = modelRecord;
|
||||||
|
|
||||||
// build a context with the initialized instance to create
|
// build a context with the initialized instance to create
|
||||||
var context = new CreateContentContext {
|
var context = new CreateContentContext {
|
||||||
Id = modelRecord.Id,
|
Id = modelRecord.Id,
|
||||||
ContentType = modelRecord.ContentType.Name,
|
ContentType = modelRecord.ContentType.Name,
|
||||||
ContentItemRecord = modelRecord,
|
ContentItemRecord = modelRecord,
|
||||||
ContentItem = content.ContentItem
|
ContentItem = contentItem
|
||||||
};
|
};
|
||||||
|
|
||||||
// set the id
|
// set the id
|
||||||
|
@@ -4,9 +4,10 @@ using Orchard.UI.Models;
|
|||||||
|
|
||||||
namespace Orchard.Models {
|
namespace Orchard.Models {
|
||||||
public interface IContentManager : IDependency {
|
public interface IContentManager : IDependency {
|
||||||
IContent New(string contentType);
|
ContentItem New(string contentType);
|
||||||
IContent Get(int id);
|
void Create(ContentItem contentItem);
|
||||||
void Create(IContent contentItem);
|
|
||||||
|
ContentItem Get(int id);
|
||||||
|
|
||||||
IEnumerable<ModelTemplate> GetDisplays(IContent contentItem);
|
IEnumerable<ModelTemplate> GetDisplays(IContent contentItem);
|
||||||
IEnumerable<ModelTemplate> GetEditors(IContent contentItem);
|
IEnumerable<ModelTemplate> GetEditors(IContent contentItem);
|
||||||
|
Reference in New Issue
Block a user