Files
Umbraco-CMS/src/Umbraco.Web/PublishedCache/PublishedMember.cs

156 lines
5.8 KiB
C#
Raw Normal View History

2014-03-11 14:23:51 +11:00
using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
2014-03-11 14:23:51 +11:00
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Web.Models;
namespace Umbraco.Web.PublishedCache
{
/// <summary>
/// Exposes a member object as IPublishedContent
/// </summary>
public sealed class PublishedMember : PublishedContentBase
2014-03-11 14:23:51 +11:00
{
private readonly IMember _member;
private readonly IMembershipUser _membershipUser;
private readonly IPublishedProperty[] _properties;
2014-03-11 14:23:51 +11:00
private readonly PublishedContentType _publishedMemberType;
public PublishedMember(IMember member, PublishedContentType publishedMemberType)
2014-03-11 14:23:51 +11:00
{
_member = member ?? throw new ArgumentNullException(nameof(member));
_membershipUser = member;
_publishedMemberType = publishedMemberType ?? throw new ArgumentNullException(nameof(publishedMemberType));
_properties = PublishedProperty.MapProperties(_publishedMemberType.PropertyTypes, _member.Properties,
(t, v) => new RawValueProperty(t, this, v ?? string.Empty))
.ToArray();
2014-03-11 14:23:51 +11:00
}
#region Membership provider member properties
2016-06-03 10:57:54 +02:00
public string Email => _membershipUser.Email;
public string UserName => _membershipUser.Username;
public string PasswordQuestion => _membershipUser.PasswordQuestion;
public string Comments => _membershipUser.Comments;
public bool IsApproved => _membershipUser.IsApproved;
public bool IsLockedOut => _membershipUser.IsLockedOut;
public DateTime LastLockoutDate => _membershipUser.LastLockoutDate;
public DateTime CreationDate => _membershipUser.CreateDate;
public DateTime LastLoginDate => _membershipUser.LastLoginDate;
public DateTime LastActivityDate => _membershipUser.LastLoginDate;
public DateTime LastPasswordChangeDate => _membershipUser.LastPasswordChangeDate;
2014-03-11 14:23:51 +11:00
#endregion
#region IPublishedContent
2016-06-03 10:57:54 +02:00
public override PublishedItemType ItemType => PublishedItemType.Member;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override bool IsDraft => false;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override IPublishedContent Parent => null;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override IEnumerable<IPublishedContent> Children => Enumerable.Empty<IPublishedContent>();
public override IEnumerable<IPublishedProperty> Properties => _properties;
2014-03-11 14:23:51 +11:00
public override IPublishedProperty GetProperty(string alias, bool recurse)
{
if (recurse)
{
throw new NotSupportedException();
}
return GetProperty(alias);
}
public override IPublishedProperty GetProperty(string alias)
{
2016-06-03 10:57:54 +02:00
switch (alias.ToLowerInvariant())
{
case "Email":
return new PropertyResult("Email", Email, PropertyResultType.CustomProperty);
case "UserName":
return new PropertyResult("UserName", UserName, PropertyResultType.CustomProperty);
2016-06-03 10:57:54 +02:00
case "PasswordQuestion":
return new PropertyResult("PasswordQuestion", PasswordQuestion, PropertyResultType.CustomProperty);
case "Comments":
return new PropertyResult("Comments", Email, PropertyResultType.CustomProperty);
case "IsApproved":
return new PropertyResult("IsApproved", IsApproved, PropertyResultType.CustomProperty);
case "IsLockedOut":
return new PropertyResult("IsLockedOut", IsLockedOut, PropertyResultType.CustomProperty);
case "LastLockoutDate":
return new PropertyResult("LastLockoutDate", LastLockoutDate, PropertyResultType.CustomProperty);
case "CreateDate":
return new PropertyResult("CreateDate", CreateDate, PropertyResultType.CustomProperty);
case "LastLoginDate":
return new PropertyResult("LastLoginDate", LastLoginDate, PropertyResultType.CustomProperty);
case "LastPasswordChangeDate":
return new PropertyResult("LastPasswordChangeDate", LastPasswordChangeDate, PropertyResultType.CustomProperty);
}
2014-03-11 14:23:51 +11:00
return _properties.FirstOrDefault(x => x.PropertyTypeAlias.InvariantEquals(alias));
}
2016-06-03 10:57:54 +02:00
public override PublishedContentType ContentType => _publishedMemberType;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int Id => _member.Id;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override Guid Key => _member.Key;
2014-03-11 14:23:51 +11:00
public override int TemplateId
{
get { throw new NotSupportedException(); }
}
2016-06-03 10:57:54 +02:00
public override int SortOrder => 0;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override string Name => _member.Name;
2014-03-11 14:23:51 +11:00
public override string UrlName
{
get { throw new NotSupportedException(); }
}
2016-06-03 10:57:54 +02:00
public override string DocumentTypeAlias => _member.ContentTypeAlias;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int DocumentTypeId => _member.ContentType.Id;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
//TODO: ARGH! need to fix this - this is not good because it uses ApplicationContext.Current
public override string WriterName => _member.GetCreatorProfile().Name;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
//TODO: ARGH! need to fix this - this is not good because it uses ApplicationContext.Current
public override string CreatorName => _member.GetCreatorProfile().Name;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int WriterId => _member.CreatorId;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override int CreatorId => _member.CreatorId;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override string Path => _member.Path;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override DateTime CreateDate => _member.CreateDate;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override DateTime UpdateDate => _member.UpdateDate;
2014-03-11 14:23:51 +11:00
2016-06-03 10:57:54 +02:00
public override Guid Version => _member.Version;
public override int Level => _member.Level;
2014-03-11 14:23:51 +11:00
#endregion
}
}