I am creating an Automapper mapping between mine AccountEditViewModel(the View Model used to edit the user) and mine User(the data model representing the user in the database). If the password field is filled in, I want to encrypt this password and save it, however, if it is zero, I want to keep the old password. I tried the code below, but this is wrong, model.Ignore () does not return a string value. What is the best way to get around this. Can I accomplish this using a method ForMember()or do I need a custom converter?
Mapper.CreateMap<AccountEditViewModel, User>()
.ForMember(model => model.Password, model => model.MapFrom(user => user.Password != null ? EncryptPassword(user.Password) : model.Ignore()));
source
share