Adding an interface for common aspect

--HG--
extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041965
This commit is contained in:
loudej
2009-11-23 22:50:58 +00:00
parent 37b270dcab
commit e66ecece0d
6 changed files with 47 additions and 30 deletions

View File

@@ -2,36 +2,41 @@
using Orchard.Core.Common.Records;
using Orchard.Core.Common.Utilities;
using Orchard.Models;
using Orchard.Models.Aspects;
using Orchard.Security;
namespace Orchard.Core.Common.Models {
public class CommonAspect : ContentPart<CommonRecord> {
public class CommonAspect : ContentPart<CommonRecord>, ICommonAspect {
private readonly LazyField<IUser> _owner = new LazyField<IUser>();
private readonly LazyField<IContent> _container = new LazyField<IContent>();
public IUser Owner {
public LazyField<IUser> OwnerField {
get { return _owner; }
}
public LazyField<IContent> ContainerField {
get { return _container; }
}
DateTime? ICommonAspect.CreatedUtc {
get { return Record.CreatedUtc;}
set { Record.CreatedUtc = value;}
}
DateTime? ICommonAspect.ModifiedUtc {
get { return Record.ModifiedUtc;}
set { Record.ModifiedUtc = value;}
}
IUser ICommonAspect.Owner {
get { return _owner.Value; }
set { _owner.Value = value; }
}
public IContent Container {
IContent ICommonAspect.Container {
get { return _container.Value; }
set { _container.Value = value; }
}
internal void OnGetOwner(Func<IUser> loader) {
_owner.Loader(loader);
}
internal void OnSetOwner(Func<IUser,IUser> setter) {
_owner.Setter(setter);
}
internal void OnGetContainer(Func<IContent> loader) {
_container.Loader(loader);
}
internal void OnSetContainer(Func<IContent, IContent> setter) {
_container.Setter(setter);
}
}
}

View File

@@ -2,6 +2,7 @@ using Orchard.Core.Common.Models;
using Orchard.Core.Common.Records;
using Orchard.Data;
using Orchard.Models;
using Orchard.Models.Aspects;
using Orchard.Models.Driver;
using Orchard.Security;
using Orchard.Services;
@@ -22,10 +23,10 @@ namespace Orchard.Core.Common.Providers {
_authenticationService = authenticationService;
_contentManager = contentManager;
Filters.Add(new StorageFilter<CommonRecord>(repository));
AddOnActivated<CommonAspect>(PropertySetHandlers);
AddOnCreating<CommonAspect>(DefaultTimestampsAndOwner);
AddOnLoaded<CommonAspect>(LazyLoadHandlers);
AddOnActivated<CommonAspect>(PropertySetHandlers);
Filters.Add(new StorageFilter<CommonRecord>(repository));
}
void DefaultTimestampsAndOwner(CreateContentContext context, CommonAspect instance) {
@@ -39,9 +40,7 @@ namespace Orchard.Core.Common.Providers {
// and use the current user as Owner
if (instance.Record.OwnerId == 0) {
instance.Owner = _authenticationService.GetAuthenticatedUser();
if (instance.Owner != null)
instance.Record.OwnerId = instance.Owner.Id;
((ICommonAspect)instance).Owner = _authenticationService.GetAuthenticatedUser();
}
}

View File

@@ -47,7 +47,6 @@ namespace Orchard.Sandbox.Controllers
public ActionResult Create(PageCreateViewModel model) {
var page = _contentManager.Create<SandboxPage>("sandboxpage", item => {
item.Record.Name = model.Name;
item.As<CommonAspect>().Container = CurrentSite.ContentItem;
});
return RedirectToAction("show", new { page.ContentItem.Id });
}

View File

@@ -5,7 +5,7 @@
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{5D0F00F0-26C9-4785-AD61-B85710C60EB0}</ProjectGuid>
<ProjectTypeGuids>{F85E285D-A4E0-4152-9332-AB1D724D3325};{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<ProjectTypeGuids>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Orchard.Tags</RootNamespace>
@@ -116,9 +116,8 @@
<IISUrl>
</IISUrl>
<NTLMAuthentication>False</NTLMAuthentication>
<UseCustomServer>False</UseCustomServer>
<CustomServerUrl>
</CustomServerUrl>
<UseCustomServer>True</UseCustomServer>
<CustomServerUrl>http://orchard.codeplex.com</CustomServerUrl>
<SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile>
</WebProjectProperties>
</FlavorProperties>

View File

@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Orchard.Security;
namespace Orchard.Models.Aspects {
public interface ICommonAspect : IContent {
DateTime? CreatedUtc { get; set; }
DateTime? ModifiedUtc { get; set; }
IUser Owner { get; set; }
IContent Container { get; set; }
}
}

View File

@@ -124,6 +124,7 @@
<Compile Include="Localization\Localizer.cs" />
<Compile Include="Localization\LocalizedString.cs" />
<Compile Include="Localization\NullLocalizer.cs" />
<Compile Include="Models\Aspects\ICommonAspect.cs" />
<Compile Include="Models\ContentItem.cs" />
<Compile Include="Models\Driver\ActivatedContentContext.cs" />
<Compile Include="Models\Driver\ActivatingFilter.cs" />