mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-09-19 10:07:55 +08:00
Adding an interface for common aspect
--HG-- extra : convert_revision : svn%3A5ff7c347-ad56-4c35-b696-ccb81de16e03/trunk%4041965
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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 });
|
||||
}
|
||||
|
@@ -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>
|
||||
|
14
src/Orchard/Models/Aspects/ICommonAspect.cs
Normal file
14
src/Orchard/Models/Aspects/ICommonAspect.cs
Normal 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; }
|
||||
}
|
||||
}
|
@@ -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" />
|
||||
|
Reference in New Issue
Block a user