namespace AAIntegration.SimmonsBank.API.Config; using AutoMapper; using AAIntegration.SimmonsBank.API.Entities; using AAIntegration.SimmonsBank.API.Models.Users; using AAIntegration.SimmonsBank.API.Models.Accounts; using AAIntegration.SimmonsBank.API.Services; using System.Runtime.Serialization; using AAIntegration.SimmonsBank.API.Models.Transactions; public class AutoMapperProfile : Profile { public AutoMapperProfile() { // UserUpdateRequest -> User CreateMap() .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; } )); // AccountUpdateRequest -> Account CreateMap(); // AccountCreateRequest -> Account CreateMap(); /*.ForMember( dest => dest.OwnerId, opt => opt.MapFrom(src => src.Owner) ); /*.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; return true; } ))*/ // Account -> AccountGet CreateMap() .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; return true; } )); // Transaction -> TransactionDto CreateMap() .ForMember(dest => dest.DebitAccountId, opt => opt.MapFrom(src => src.DebitAccount.Id)) .ForMember(dest => dest.CreditAccountId, opt => opt.MapFrom(src => src.CreditAccount.Id)) .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; return true; } )); } }