Implemented auto-mapper for mapping and converted over the user mappings. Got the gravatar directive working now too. Removed all umbracoUseMediumTrust settings.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using AutoMapper;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
@@ -7,36 +8,39 @@ namespace Umbraco.Web.Models.Mapping
|
||||
{
|
||||
internal class UserModelMapper
|
||||
{
|
||||
public UserDetail ToUserDetail(IUser user)
|
||||
/// <summary>
|
||||
/// Configures the automapper mappings
|
||||
/// </summary>
|
||||
internal static void Configure()
|
||||
{
|
||||
var detail = new UserDetail
|
||||
{
|
||||
Name = user.Name,
|
||||
Email = user.Email,
|
||||
Language = user.Language
|
||||
};
|
||||
var result = user.Id.TryConvertTo<int>();
|
||||
Mapper.CreateMap<IUser, UserDetail>()
|
||||
.ForMember(detail => detail.UserId, opt => opt.MapFrom(user => GetIntId(user.Id)))
|
||||
.ForMember(
|
||||
detail => detail.EmailHash,
|
||||
opt => opt.MapFrom(user => user.Email.ToLowerInvariant().Trim().ToMd5()));
|
||||
Mapper.CreateMap<IProfile, UserBasic>()
|
||||
.ForMember(detail => detail.UserId, opt => opt.MapFrom(profile => GetIntId(profile.Id)));
|
||||
}
|
||||
|
||||
private static int GetIntId(object id)
|
||||
{
|
||||
var result = id.TryConvertTo<int>();
|
||||
if (result.Success == false)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot convert the profile to a " + typeof(UserDetail).Name + " object since the id is not an integer");
|
||||
throw new InvalidOperationException(
|
||||
"Cannot convert the profile to a " + typeof(UserDetail).Name + " object since the id is not an integer");
|
||||
}
|
||||
detail.UserId = result.Result;
|
||||
return detail;
|
||||
return result.Result;
|
||||
}
|
||||
|
||||
public UserDetail ToUserDetail(IUser user)
|
||||
{
|
||||
return Mapper.Map<UserDetail>(user);
|
||||
}
|
||||
|
||||
public UserBasic ToUserBasic(IProfile profile)
|
||||
{
|
||||
var user = new UserBasic
|
||||
{
|
||||
Name = profile.Name
|
||||
};
|
||||
var result = profile.Id.TryConvertTo<int>();
|
||||
if (result.Success == false)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot convert the profile to a " + typeof(UserBasic).Name + " object since the id is not an integer");
|
||||
}
|
||||
user.UserId = result.Result;
|
||||
return user;
|
||||
return Mapper.Map<UserDetail>(profile);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user