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.Models.Envelopes; using AAIntegration.SimmonsBank.API.Models.CurrencyType; using AAIntegration.SimmonsBank.API.Services; using System.Runtime.Serialization; using AAIntegration.SimmonsBank.API.Models.Transactions; using AAIntegration.SimmonsBank.API.Models.Autoclass; public class AutoMapperProfile : Profile { public AutoMapperProfile() { // User -> AuthenticateResponse CreateMap(); // RegisterRequest -> User CreateMap(); // 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 role if (x.DestinationMember.Name == "Role" && src.Role == null) 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; } )); // AccountHistorical -> AccountHistoricalDTO CreateMap(); // EnvelopeHistorical -> EnvelopeHistoricalDTO CreateMap(); // Envelope -> EnvelopeDTO 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; } )); // EnvelopeFundingMethod -> EnvelopeFundingMethodDTO 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)) .ForMember(dest => dest.DebitEnvelopeId, opt => opt.MapFrom(src => src.DebitEnvelope.Id)) .ForMember(dest => dest.CreditEnvelopeId, opt => opt.MapFrom(src => src.CreditEnvelope.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; } )); // CurrencyTypeCreateRequest -> CurrencyType 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; } )); // AutoclassExpression <-> AutoclassExpressionCreateRequest CreateMap(); 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; } )); CreateMap(); CreateMap(); // AutoclassChange <-> AutoclassChangeCreateRequest CreateMap(); 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; } )); // AutoclassRule <-> AutoclassRuleCreateRequest CreateMap() //.ForMember(d => d.Account, opt => opt.MapFrom(src => src.Account.Id)) .ReverseMap();/* CreateMap() .ForMember(d => d.Account, opt => opt.MapFrom(src => src)) .ForAllMembers(x => x.Condition( (src, dest, prop) => { if (dest.GetType() == typeof(Account)) { } // ignore both null & empty string properties if (prop == null) return false; if (prop.GetType() == typeof(string) && string.IsNullOrEmpty((string)prop)) return false; return true; } )); CreateMap() .ForMember(d => d.Id, opt => opt.MapFrom(src => src.Account)) .ForAllMembers(x => x.Condition( (src, dest, prop) => { src.UseDestinationValue(); // ignore both null & empty string properties if (prop == null) return false; if (prop.GetType() == typeof(string) && string.IsNullOrEmpty((string)prop)) return false; return true; } ));*/ // AutoclassRule -> AutoclassRuleDTO CreateMap() .ForMember(dest => dest.AccountId, opt => opt.MapFrom(src => src.Account.Id)); } }