Skip to content

Instantly share code, notes, and snippets.

@mhinze
Created July 3, 2009 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mhinze/140174 to your computer and use it in GitHub Desktop.
Save mhinze/140174 to your computer and use it in GitHub Desktop.
nerddinner automapper configuration
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