diff --git a/src/Umbraco.Core/EventArgs.cs b/src/Umbraco.Core/EventArgs.cs
index 406cc780db..3e67239fa4 100644
--- a/src/Umbraco.Core/EventArgs.cs
+++ b/src/Umbraco.Core/EventArgs.cs
@@ -3,8 +3,7 @@
namespace Umbraco.Core
{
//Publishing Events
- public class PublishEventArgs : System.ComponentModel.CancelEventArgs { }
- public class UnPublishEventArgs : System.ComponentModel.CancelEventArgs { }
+ public class PublishingEventArgs : System.ComponentModel.CancelEventArgs { }
public class SendToPublishEventArgs : System.ComponentModel.CancelEventArgs { }
//Moving Content Events
diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs
index 4dbde74b63..ba72f6d099 100644
--- a/src/Umbraco.Core/Models/Content.cs
+++ b/src/Umbraco.Core/Models/Content.cs
@@ -2,6 +2,7 @@
using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
+using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Models
{
@@ -18,6 +19,7 @@ namespace Umbraco.Core.Models
private string _language;
private DateTime? _releaseDate;
private DateTime? _expireDate;
+ private IProfile _writer;
///
/// Constructor for creating a Content object
@@ -46,6 +48,7 @@ namespace Umbraco.Core.Models
private static readonly PropertyInfo LanguageSelector = ExpressionHelper.GetPropertyInfo(x => x.Language);
private static readonly PropertyInfo ReleaseDateSelector = ExpressionHelper.GetPropertyInfo(x => x.ReleaseDate);
private static readonly PropertyInfo ExpireDateSelector = ExpressionHelper.GetPropertyInfo(x => x.ExpireDate);
+ private static readonly PropertyInfo WriterSelector = ExpressionHelper.GetPropertyInfo(x => x.Writer);
///
/// Path to the template used by this Content
@@ -132,10 +135,10 @@ namespace Umbraco.Core.Models
set
{
if(value.HasValue && value.Value > DateTime.UtcNow && Published)
- ChangePublishedState(false);
+ _published = false;
if (value.HasValue && value.Value < DateTime.UtcNow && !Published)
- ChangePublishedState(true);
+ _published = true;
_releaseDate = value;
OnPropertyChanged(ReleaseDateSelector);
@@ -152,13 +155,27 @@ namespace Umbraco.Core.Models
set
{
if(value.HasValue && DateTime.UtcNow > value.Value && Published)
- ChangePublishedState(false);
+ _published = false;
_expireDate = value;
OnPropertyChanged(ExpireDateSelector);
}
}
+ ///
+ /// IProfile of the user who wrote/updated this Content
+ ///
+ [DataMember]
+ public virtual IProfile Writer
+ {
+ get { return _writer; }
+ set
+ {
+ _writer = value;
+ OnPropertyChanged(WriterSelector);
+ }
+ }
+
///
/// Gets the ContentType used by this content object
///
diff --git a/src/Umbraco.Core/Models/ContentBase.cs b/src/Umbraco.Core/Models/ContentBase.cs
index 1f61bce6cd..6caa29d8a1 100644
--- a/src/Umbraco.Core/Models/ContentBase.cs
+++ b/src/Umbraco.Core/Models/ContentBase.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Reflection;
using System.Runtime.Serialization;
using Umbraco.Core.Models.EntityBase;
+using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Models
{
@@ -20,7 +21,7 @@ namespace Umbraco.Core.Models
private int _sortOrder;
private int _level;
private string _path;
- private int _userId;
+ private IProfile _user;
private bool _trashed;
private int _contentTypeId;
private PropertyCollection _properties;
@@ -44,7 +45,7 @@ namespace Umbraco.Core.Models
private static readonly PropertyInfo SortOrderSelector = ExpressionHelper.GetPropertyInfo(x => x.SortOrder);
private static readonly PropertyInfo LevelSelector = ExpressionHelper.GetPropertyInfo(x => x.Level);
private static readonly PropertyInfo PathSelector = ExpressionHelper.GetPropertyInfo(x => x.Path);
- private static readonly PropertyInfo UserIdSelector = ExpressionHelper.GetPropertyInfo(x => x.UserId);
+ private static readonly PropertyInfo UserSelector = ExpressionHelper.GetPropertyInfo(x => x.User);
private static readonly PropertyInfo TrashedSelector = ExpressionHelper.GetPropertyInfo(x => x.Trashed);
private static readonly PropertyInfo DefaultContentTypeIdSelector = ExpressionHelper.GetPropertyInfo(x => x.ContentTypeId);
private readonly static PropertyInfo PropertyCollectionSelector = ExpressionHelper.GetPropertyInfo(x => x.Properties);
@@ -136,16 +137,16 @@ namespace Umbraco.Core.Models
}
///
- /// Id of the user who created this Content
+ /// IProfile of the user who created this Content
///
[DataMember]
- public virtual int UserId
+ public virtual IProfile User
{
- get { return _userId; }
+ get { return _user; }
set
{
- _userId = value;
- OnPropertyChanged(UserIdSelector);
+ _user = value;
+ OnPropertyChanged(UserSelector);
}
}
diff --git a/src/Umbraco.Core/Models/IContent.cs b/src/Umbraco.Core/Models/IContent.cs
index d66a8bbceb..0c661d6610 100644
--- a/src/Umbraco.Core/Models/IContent.cs
+++ b/src/Umbraco.Core/Models/IContent.cs
@@ -1,4 +1,5 @@
using System;
+using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Models
{
@@ -33,6 +34,11 @@ namespace Umbraco.Core.Models
///
DateTime? ExpireDate { get; set; }
+ ///
+ /// Profile of the user who wrote the Content
+ ///
+ IProfile Writer { get; set; }
+
///
/// Gets the ContentType used by this content object
///
diff --git a/src/Umbraco.Core/Models/IContentBase.cs b/src/Umbraco.Core/Models/IContentBase.cs
index db7d469adb..5af5684726 100644
--- a/src/Umbraco.Core/Models/IContentBase.cs
+++ b/src/Umbraco.Core/Models/IContentBase.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Models.EntityBase;
+using Umbraco.Core.Models.Membership;
namespace Umbraco.Core.Models
{
@@ -41,9 +42,9 @@ namespace Umbraco.Core.Models
string Path { get; set; }
///
- /// Id of the user who created the Content
+ /// Profile of the user who created the Content
///
- int UserId { get; set; }
+ IProfile User { get; set; }
///
/// Boolean indicating whether this Content is Trashed or not.
diff --git a/src/Umbraco.Core/Models/Membership/IMembershipUser.cs b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs
new file mode 100644
index 0000000000..b54f8d371d
--- /dev/null
+++ b/src/Umbraco.Core/Models/Membership/IMembershipUser.cs
@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+
+namespace Umbraco.Core.Models.Membership
+{
+ internal interface IMembershipUser : IMembershipUserId
+ {
+ object Id { get; set; }
+ string Username { get; set; }
+ string Email { get; set; }
+ string Password { get; set; }
+ string PasswordQuestion { get; set; }
+ string PasswordAnswer { get; set; }
+ string Comments { get; set; }
+ bool IsApproved { get; set; }
+ bool IsOnline { get; set; }
+ bool IsLockedOut { get; set; }
+ DateTime CreationDate { get; set; }
+ DateTime LastLoginDate { get; set; }
+ DateTime LastActivityDate { get; set; }
+ DateTime LastPasswordChangeDate { get; set; }
+ DateTime LastLockoutDate { get; set; }
+
+ object ProfileId { get; set; }
+ IEnumerable
/// The to publish along with its children
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if publishing succeeded, otherwise False
- public bool PublishWithChildren(IContent content, int userId)
+ public bool PublishWithChildren(IContent content, int userId = -1)
{
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
@@ -282,6 +295,7 @@ namespace Umbraco.Web.Services
//Only loop through content where the Published property has been updated
foreach (var item in list.Where(x => ((ICanBeDirty)x).IsPropertyDirty("Published")))
{
+ SetWriter(item, userId);
repository.AddOrUpdate(item);
}
@@ -299,9 +313,9 @@ namespace Umbraco.Web.Services
/// UnPublishes a single object
///
/// The to publish
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if unpublishing succeeded, otherwise False
- public bool UnPublish(IContent content, int userId)
+ public bool UnPublish(IContent content, int userId = -1)
{
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
@@ -324,6 +338,7 @@ namespace Umbraco.Web.Services
{
foreach (var child in children)
{
+ SetWriter(child, userId);
repository.AddOrUpdate(child);
}
}
@@ -367,9 +382,9 @@ namespace Umbraco.Web.Services
/// Saves and Publishes a single object
///
/// The to save and publish
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if publishing succeeded, otherwise False
- public bool SaveAndPublish(IContent content, int userId)
+ public bool SaveAndPublish(IContent content, int userId = -1)
{
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
@@ -395,6 +410,7 @@ namespace Umbraco.Web.Services
bool published = _publishingStrategy.Publish(content, userId);
if (published)
{
+ SetWriter(content, userId);
repository.AddOrUpdate(content);
_unitOfWork.Commit();
@@ -409,10 +425,13 @@ namespace Umbraco.Web.Services
/// Saves a single object
///
/// The to save
- /// Id of the User saving the Content
- public void Save(IContent content, int userId)
+ /// Optional Id of the User saving the Content
+ public void Save(IContent content, int userId = -1)
{
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
+
+ SetWriter(content, userId);
+
repository.AddOrUpdate(content);
_unitOfWork.Commit();
}
@@ -421,12 +440,13 @@ namespace Umbraco.Web.Services
/// Saves a collection of objects
///
/// Collection of to save
- /// Id of the User saving the Content
- public void Save(IEnumerable contents, int userId)
+ /// Optional Id of the User saving the Content
+ public void Save(IEnumerable contents, int userId = -1)
{
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
foreach (var content in contents)
{
+ SetWriter(content, userId);
repository.AddOrUpdate(content);
}
_unitOfWork.Commit();
@@ -459,13 +479,14 @@ namespace Umbraco.Web.Services
///
/// Please note that this method will completely remove the Content from the database
/// The to delete
- /// Id of the User deleting the Content
- public void Delete(IContent content, int userId)
+ /// Optional Id of the User deleting the Content
+ public void Delete(IContent content, int userId = -1)
{
//TODO Ensure that content is unpublished when deleted
//TODO This method should handle/react to errors when there is a constraint issue with the content being deleted
//TODO Children should either be deleted or moved to the recycle bin
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
+ SetWriter(content, userId);
repository.Delete(content);
_unitOfWork.Commit();
}
@@ -475,12 +496,13 @@ namespace Umbraco.Web.Services
///
/// Move an item to the Recycle Bin will result in the item being unpublished
/// The to delete
- /// Id of the User deleting the Content
- public void MoveToRecycleBin(IContent content, int userId)
+ /// Optional Id of the User deleting the Content
+ public void MoveToRecycleBin(IContent content, int userId = -1)
{
//TODO If content item has children those should also be moved to the recycle bin
//TODO Unpublish deleted content + children
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
+ SetWriter(content, userId);
content.ChangeTrashedState(true);
repository.AddOrUpdate(content);
_unitOfWork.Commit();
@@ -496,9 +518,11 @@ namespace Umbraco.Web.Services
///
/// The to move
/// Id of the Content's new Parent
- /// Id of the User moving the Content
- public void Move(IContent content, int parentId, int userId)
+ /// Optional Id of the User moving the Content
+ public void Move(IContent content, int parentId, int userId = -1)
{
+ SetWriter(content, userId);
+
//If Content is being moved away from Recycle Bin, its state should be un-trashed
if(content.Trashed && parentId != -20)
{
@@ -543,9 +567,9 @@ namespace Umbraco.Web.Services
///
/// The to copy
/// Id of the Content's new Parent
- /// Id of the User copying the Content
+ /// Optional Id of the User copying the Content
/// The newly created object
- public IContent Copy(IContent content, int parentId, int userId)
+ public IContent Copy(IContent content, int parentId, int userId = -1)
{
var copy = ((Content) content).Clone();
copy.ParentId = parentId;
@@ -553,6 +577,8 @@ namespace Umbraco.Web.Services
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
+ SetWriter(content, userId);
+
repository.AddOrUpdate(copy);
_unitOfWork.Commit();
@@ -563,9 +589,9 @@ namespace Umbraco.Web.Services
/// Sends an to Publication, which executes handlers and events for the 'Send to Publication' action.
///
/// The to send to publication
- /// Id of the User issueing the send to publication
+ /// Optional Id of the User issueing the send to publication
/// True if sending publication was succesfull otherwise false
- public bool SendToPublication(IContent content, int userId)
+ public bool SendToPublication(IContent content, int userId = -1)
{
//TODO Implement something similar to this
/*SendToPublishEventArgs e = new SendToPublishEventArgs();
@@ -592,17 +618,70 @@ namespace Umbraco.Web.Services
///
/// Id of the being rolled back
/// Id of the version to rollback to
- /// Id of the User issueing the rollback of the Content
+ /// Optional Id of the User issueing the rollback of the Content
/// The newly created object
- public IContent Rollback(int id, Guid versionId, int userId)
+ public IContent Rollback(int id, Guid versionId, int userId = -1)
{
var repository = RepositoryResolver.ResolveByType(_unitOfWork);
var content = repository.GetByVersion(id, versionId);
+ SetUser(content, userId);
+ SetWriter(content, userId);
+
repository.AddOrUpdate(content);
_unitOfWork.Commit();
return content;
}
+
+ ///
+ /// Updates a content object with the User (id), who created the content.
+ ///
+ /// object to update
+ /// Optional Id of the User
+ private void SetUser(IContent content, int userId)
+ {
+ if(userId > -1)
+ {
+ //If a user id was passed in we use that
+ content.User = new Profile(userId, "");
+ }
+ else if(_userService != null)
+ {
+ //If the UserService has been set for this instance of the ServiceContext
+ //we retrieve the current users id from there.
+ content.User = _userService.GetCurrentBackOfficeUser();
+ }
+ else
+ {
+ //Otherwise we default to Admin user, which should always exist (almost always)
+ content.User = new Profile(0, "Administrator");
+ }
+ }
+
+ ///
+ /// Updates a content object with a Writer (user id), who updated the content.
+ ///
+ /// object to update
+ /// Optional Id of the Writer
+ private void SetWriter(IContent content, int userId)
+ {
+ if (userId > -1)
+ {
+ //If a user id was passed in we use that
+ content.Writer = new Profile(userId, "");
+ }
+ else if (_userService != null)
+ {
+ //If the UserService has been set for this instance of the ServiceContext
+ //we retrieve the current users id from there.
+ content.Writer = _userService.GetCurrentBackOfficeUser();
+ }
+ else
+ {
+ //Otherwise we default to Admin user, which should always exist (almost always)
+ content.Writer = new Profile(0, "Administrator");
+ }
+ }
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Services/IContentService.cs b/src/Umbraco.Web/Services/IContentService.cs
index 46f9b8b5bd..7b9359e2ab 100644
--- a/src/Umbraco.Web/Services/IContentService.cs
+++ b/src/Umbraco.Web/Services/IContentService.cs
@@ -15,8 +15,9 @@ namespace Umbraco.Web.Services
///
/// Id of Parent for content
/// Alias of the
+ /// Optional id of the user creating the content
///
- IContent CreateContent(int parentId, string contentTypeAlias);
+ IContent CreateContent(int parentId, string contentTypeAlias, int userId = -1);
//TODO Add CreateNewVersion method? Its currently used in the Document API when Publishing - latest version is published,
//but then a new version is created so latest version is not published.
@@ -84,55 +85,55 @@ namespace Umbraco.Web.Services
///
/// Re-Publishes all Content
///
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if publishing succeeded, otherwise False
- bool RePublishAll(int userId);
+ bool RePublishAll(int userId = -1);
///
/// Publishes a single object
///
/// The to publish
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if publishing succeeded, otherwise False
- bool Publish(IContent content, int userId);
+ bool Publish(IContent content, int userId = -1);
///
/// Publishes a object and all its children
///
/// The to publish along with its children
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if publishing succeeded, otherwise False
- bool PublishWithChildren(IContent content, int userId);
+ bool PublishWithChildren(IContent content, int userId = -1);
///
/// UnPublishes a single object
///
/// The to publish
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if unpublishing succeeded, otherwise False
- bool UnPublish(IContent content, int userId);
+ bool UnPublish(IContent content, int userId = -1);
///
/// Saves and Publishes a single object
///
/// The to save and publish
- /// Id of the User issueing the publishing
+ /// Optional Id of the User issueing the publishing
/// True if publishing succeeded, otherwise False
- bool SaveAndPublish(IContent content, int userId);
+ bool SaveAndPublish(IContent content, int userId = -1);
///
/// Saves a single object
///
/// The to save
- /// Id of the User saving the Content
- void Save(IContent content, int userId);
+ /// Optional Id of the User saving the Content
+ void Save(IContent content, int userId = -1);
///
/// Saves a collection of objects
///
/// Collection of to save
- /// Id of the User saving the Content
- void Save(IEnumerable contents, int userId);
+ /// Optional Id of the User saving the Content
+ void Save(IEnumerable contents, int userId = -1);
///
/// Deletes all content of specified type. All children of deleted content is moved to Recycle Bin.
@@ -146,24 +147,24 @@ namespace Umbraco.Web.Services
///
/// Please note that this method will completely remove the Content from the database
/// The to delete
- /// Id of the User deleting the Content
- void Delete(IContent content, int userId);
+ /// Optional Id of the User deleting the Content
+ void Delete(IContent content, int userId = -1);
///
/// Deletes an object by moving it to the Recycle Bin
///
/// Move an item to the Recycle Bin will result in the item being unpublished
/// The to delete
- /// Id of the User deleting the Content
- void MoveToRecycleBin(IContent content, int userId);
+ /// Optional Id of the User deleting the Content
+ void MoveToRecycleBin(IContent content, int userId = -1);
///
/// Moves an object to a new location
///
/// The to move
/// Id of the Content's new Parent
- /// Id of the User moving the Content
- void Move(IContent content, int parentId, int userId);
+ /// Optional Id of the User moving the Content
+ void Move(IContent content, int parentId, int userId = -1);
///
/// Empties the Recycle Bin by deleting all that resides in the bin
@@ -176,17 +177,17 @@ namespace Umbraco.Web.Services
///
/// The to copy
/// Id of the Content's new Parent
- /// Id of the User copying the Content
+ /// Optional Id of the User copying the Content
/// The newly created object
- IContent Copy(IContent content, int parentId, int userId);
+ IContent Copy(IContent content, int parentId, int userId = -1);
///
/// Sends an to Publication, which executes handlers and events for the 'Send to Publication' action.
///
/// The to send to publication
- /// Id of the User issueing the send to publication
+ /// Optional Id of the User issueing the send to publication
/// True if sending publication was succesfull otherwise false
- bool SendToPublication(IContent content, int userId);
+ bool SendToPublication(IContent content, int userId = -1);
///
/// Rollback an object to a previous version.
@@ -194,8 +195,8 @@ namespace Umbraco.Web.Services
///
/// Id of the being rolled back
/// Id of the version to rollback to
- /// Id of the User issueing the rollback of the Content
+ /// Optional Id of the User issueing the rollback of the Content
/// The newly created object
- IContent Rollback(int id, Guid versionId, int userId);
+ IContent Rollback(int id, Guid versionId, int userId = -1);
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Services/IUserService.cs b/src/Umbraco.Web/Services/IUserService.cs
new file mode 100644
index 0000000000..95c2c2a73d
--- /dev/null
+++ b/src/Umbraco.Web/Services/IUserService.cs
@@ -0,0 +1,16 @@
+using Umbraco.Core.Models.Membership;
+
+namespace Umbraco.Web.Services
+{
+ ///
+ /// Defines the UserService, which is an easy access to operations involving and eventually Users and Members.
+ ///
+ public interface IUserService : IService
+ {
+ ///
+ /// Gets an for the current BackOffice User
+ ///
+ /// containing the Name and Id of the logged in BackOffice User
+ IProfile GetCurrentBackOfficeUser();
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Services/ServiceContext.cs b/src/Umbraco.Web/Services/ServiceContext.cs
index 0ccade4292..bba2e2e87d 100644
--- a/src/Umbraco.Web/Services/ServiceContext.cs
+++ b/src/Umbraco.Web/Services/ServiceContext.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Concurrent;
+using System.Web;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Web.Publishing;
@@ -12,19 +13,19 @@ namespace Umbraco.Web.Services
///
public class ServiceContext
{
- #region Singleton
- private static readonly Lazy lazy = new Lazy(() => new ServiceContext());
-
- public static ServiceContext Current { get { return lazy.Value; } }
-
- private ServiceContext()
+ internal ServiceContext(HttpContextBase httpContext)
{
- if(_cache.IsEmpty)
+ _httpContext = httpContext;
+
+ if (_cache.IsEmpty)
{
BuildServiceCache();
}
}
- #endregion
+
+ public static ServiceContext Current { get; internal set; }
+
+ private readonly HttpContextBase _httpContext;
private readonly ConcurrentDictionary _cache = new ConcurrentDictionary();
@@ -37,7 +38,9 @@ namespace Umbraco.Web.Services
var fileProvider = new FileUnitOfWorkProvider();
var publishingStrategy = new PublishingStrategy();
- var contentService = new ContentService(provider, publishingStrategy);
+ var userService = new UserService(_httpContext);
+
+ var contentService = new ContentService(provider, publishingStrategy, userService);
_cache.AddOrUpdate(typeof (IContentService).Name, contentService, (x, y) => contentService);
var mediaService = new MediaService(provider);
diff --git a/src/Umbraco.Web/Services/ServiceFactory.cs b/src/Umbraco.Web/Services/ServiceFactory.cs
index db4432d869..298df0365d 100644
--- a/src/Umbraco.Web/Services/ServiceFactory.cs
+++ b/src/Umbraco.Web/Services/ServiceFactory.cs
@@ -6,12 +6,14 @@
///
public static class ServiceFactory
{
+ private static readonly ServiceContext ServiceContext = new ServiceContext(null);
+
///
/// Gets the
///
public static IContentService ContentService
{
- get { return ServiceContext.Current.ContentService; }
+ get { return ServiceContext.ContentService; }
}
///
@@ -19,7 +21,7 @@
///
public static IContentTypeService ContentTypeService
{
- get { return ServiceContext.Current.ContentTypeService; }
+ get { return ServiceContext.ContentTypeService; }
}
///
@@ -27,7 +29,7 @@
///
public static IDataTypeService DataTypeService
{
- get { return ServiceContext.Current.DataTypeService; }
+ get { return ServiceContext.DataTypeService; }
}
///
@@ -35,7 +37,7 @@
///
public static IFileService FileService
{
- get { return ServiceContext.Current.FileService; }
+ get { return ServiceContext.FileService; }
}
///
@@ -43,7 +45,7 @@
///
public static ILocalizationService LocalizationService
{
- get { return ServiceContext.Current.LocalizationService; }
+ get { return ServiceContext.LocalizationService; }
}
///
@@ -51,7 +53,7 @@
///
public static IMediaService MediaService
{
- get { return ServiceContext.Current.MediaService; }
+ get { return ServiceContext.MediaService; }
}
///
@@ -59,7 +61,7 @@
///
public static IMacroService MacroService
{
- get { return ServiceContext.Current.MacroService; }
+ get { return ServiceContext.MacroService; }
}
}
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Services/UserService.cs b/src/Umbraco.Web/Services/UserService.cs
new file mode 100644
index 0000000000..fd37ce92e6
--- /dev/null
+++ b/src/Umbraco.Web/Services/UserService.cs
@@ -0,0 +1,76 @@
+using System;
+using System.Web;
+using Umbraco.Core;
+using Umbraco.Core.Models.Membership;
+using Umbraco.Core.Models.Rdbms;
+using Umbraco.Core.Persistence;
+using umbraco;
+
+namespace Umbraco.Web.Services
+{
+ ///
+ /// Represents the UserService, which is an easy access to operations involving and eventually Users and Members.
+ ///
+ public class UserService : IUserService
+ {
+ private readonly HttpContextBase _httpContext;
+
+ public UserService(HttpContextBase httpContext)
+ {
+ _httpContext = httpContext;
+ }
+
+ #region Implementation of IUserService
+
+ ///
+ /// Gets an for the current BackOffice User
+ ///
+ /// containing the Name and Id of the logged in BackOffice User
+ public IProfile GetCurrentBackOfficeUser()
+ {
+ var cookie = _httpContext.Request.Cookies["UMB_UCONTEXT"];
+
+ Mandate.That(cookie != null, () => new ArgumentException("The Cookie containing the UserContext Guid Id was null", "Cookie"));
+
+ string contextId = cookie.Value;
+ string cacheKey = string.Concat("UmbracoUserContext", contextId);
+
+ int userId = 0;
+
+ if(HttpRuntime.Cache[cacheKey] == null)
+ {
+ userId =
+ DatabaseFactory.Current.Database.ExecuteScalar(
+ "select userID from umbracoUserLogins where contextID = @ContextId",
+ new {ContextId = new Guid(contextId)});
+
+ HttpRuntime.Cache.Insert(cacheKey, userId,
+ null,
+ System.Web.Caching.Cache.NoAbsoluteExpiration,
+ new TimeSpan(0, (int) (GlobalSettings.TimeOutInMinutes/10), 0));
+ }
+ else
+ {
+ userId = (int) HttpRuntime.Cache[cacheKey];
+ }
+
+ //Not too happy with this db lookup, but it'll improve once there is a UserRepository with caching
+ var userDto = GetUserById(userId);
+
+ var profile = new Profile(userId, userDto.UserName);
+ return profile;
+ }
+
+ ///
+ /// Gets a User dto from the database.
+ ///
+ /// Id of the User to retrieve
+ ///
+ private UserDto GetUserById(int id)
+ {
+ return DatabaseFactory.Current.Database.FirstOrDefault("WHERE id = @Id", new {Id = id});
+ }
+
+ #endregion
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index b4d76c4dab..563de6f82f 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -327,11 +327,13 @@
+
+ ASPXCodeBehind
diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs
index bfdcaf0622..dc391317b8 100644
--- a/src/Umbraco.Web/UmbracoContext.cs
+++ b/src/Umbraco.Web/UmbracoContext.cs
@@ -50,6 +50,7 @@ namespace Umbraco.Web
HttpContext = httpContext;
Application = applicationContext;
+ ServiceContext = new ServiceContext(httpContext);
RoutesCache = routesCache;
// set the urls...
@@ -105,6 +106,11 @@ namespace Umbraco.Web
///
public ApplicationContext Application { get; private set; }
+ ///
+ /// Gets the current ServiceContext
+ ///
+ public ServiceContext ServiceContext { get; private set; }
+
///
/// Gets the
///