i have two classe User (Destination) and UserViewModel (Source) :
public class User
{
public int Id{ get; set; }
public string Username{ get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public DateTime? DateOfBirth { get; set; }
public Enums.Sex Sex { get; set; }
public byte[] ProfilePicture { get; set; }
public int Score { get; set; }
}
public class ProfileViewModel
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string PhoneNumber { get; set; }
public string Email { get; set; }
}
This is the AutoMapper config :
Mapper.Initialize(cfg =>
{
cfg.CreateMap<ProfileViewModel, User>()
.ForMember<int>(u =>u.Id, m => m.Ignore()).ForMember<string>(u=> u.UserName, m => m.Ignore());
});
I'm using it here :
public ActionResult MyProfile(ProfileViewModel m, HttpPostedFileBase profilePicture)
{
User currentUser = UserRep.GetCurrentUser(User.Identity.GetUserId());
currentUser = Mapper.Map<User>(m);
...
}
I bring the current user with all the data id, username ... and when i execute the mapping username is null and id = 0 i d'ont understand and i try with ignore() and usedestinationValue()