Created
July 3, 2009 15:15
-
-
Save mhinze/140174 to your computer and use it in GitHub Desktop.
nerddinner automapper configuration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AutoMapperConfiguration | |
{ | |
public static void Configure() | |
{ | |
Mapper.Initialize(x => x.AddProfile<ViewModelProfile>()); | |
} | |
} | |
public class ViewModelProfile : Profile | |
{ | |
protected override string ProfileName | |
{ | |
get { return "ViewModel"; } | |
} | |
protected override void Configure() | |
{ | |
AddFormatter<HtmlEncoderFormatter>(); | |
ForSourceType<DateTime>().AddFormatter<StandardDateFormatter>(); | |
CreateMap<Dinner, DinnerDetailsViewModel>() | |
.ForMember(x => x.Longitude, o => o.SkipFormatter<HtmlEncoderFormatter>()) | |
.ForMember(x => x.Latitude, o => o.SkipFormatter<HtmlEncoderFormatter>()) | |
.ForMember(x => x.IsCurrentUserRegistered, o => o.ResolveUsing<CurrentUserRegisteredResolver>()) | |
.ForMember(x => x.IsCurrentUserHosting, o => o.ResolveUsing<CurrentUserHostingResolver>()) | |
.ForMember(x => x.EventDateSortable, o => | |
{ | |
o.MapFrom(x => x.EventDate); | |
o.AddFormatter<SortableDateFormatter>(); | |
}) | |
.ForMember(x => x.EventDateShortTime, o => | |
{ | |
o.MapFrom(x => x.EventDate); | |
o.AddFormatter<ShortTimeFormatter>(); | |
}); | |
CreateMap<RSVP, DinnerDetailsViewModel.RsvpDto>() | |
.ForMember(x => x.AttendeeName, o => o.AddFormatter<AttendeeNameFormatter>()); | |
} | |
} | |
public class DinnerDetailsViewModel | |
{ | |
public string Address { get; set; } | |
public string Title { get; set; } | |
public string DinnerID { get; set; } | |
public string EventDateSortable { get; set; } | |
public string EventDate { get; set; } | |
public string EventDateShortTime { get; set; } | |
public string Country { get; set; } | |
public string Latitude { get; set; } | |
public string Longitude { get; set; } | |
public string Description { get; set; } | |
public string HostedBy { get; set; } | |
public string ContactPhone { get; set; } | |
public bool IsAnyoneRegistered { get; set; } | |
public bool IsNobodyRegistered { get; set; } | |
public bool IsCurrentUserRegistered { get; set; } | |
public bool IsCurrentUserHosting { get; set; } | |
public List<RsvpDto> RSVPs { get; set; } | |
public class RsvpDto | |
{ | |
public string AttendeeName { get; set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment