25 lines
874 B
C#

namespace AAIntegration.SimmonsBank.API.Config;
using AutoMapper;
using AAIntegration.SimmonsBank.API.Entities;
using AAIntegration.SimmonsBank.API.Models.Users;
public class AutoMapperProfile : Profile
{
public AutoMapperProfile()
{ // UserUpdateRequest -> User
CreateMap<UserUpdateRequest, User>()
.ForAllMembers(x => x.Condition(
(src, dest, prop) =>
{
// ignore both null & empty string properties
if (prop == null) return false;
if (prop.GetType() == typeof(string) && string.IsNullOrEmpty((string)prop)) return false;
// ignore null password
if (x.DestinationMember.Name == "Password" && src.Password == null) return false;
return true;
}
));
}
}