Hi,
I have two different classes which I would like to map with another class.
Here are the source classes:
public class OrderResponse
{
public int order_id { get; set; }
public int delivery_type { get; set; }
public string destination { get; set; }
public int status { get; set; }
public string status_text { get; set; }
public DateTime created_time { get; set; }
public int? terminal_id { get; set; }
public string reference_code { get; set; }
public ProductWatson product { get; set; }
public int count { get; set; }
public double total_face_value { get; set; }
public int total_fees { get; set; }
public double total_discounts { get; set; }
public double total_customer_cost { get; set; }
public bool is_completed { get; set; }
public string share_link { get; set; }
}
public class Card
{
public List<CardResponse> results { get; set; }
}
Here is the destination class which I would like to combine values from source classes
public class GameConfirmResponseDto
{
public string referenceId { get; set; }
public string productCode { get; set; }
public int quantity { get; set; }
public string productDescription { get; set; }
public string currency { get; set; }
public double unitPrice { get; set; }
public double totalPrice { get; set; }
public DateTime? purchaseStatusDate { get; set; }
[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]
public string clientTrxRef { get; set; }
public List<CouponDto> coupons { get; set; }
}
Cards will map with coupons, here is what I tried but couldn't manage to pass values to coupons.
Here is my mapping profile
CreateMap<OrderResponse, GameConfirmResponseDto>()
.ForMember(dest => dest.productCode, act => act.MapFrom(src => src.product.sku.ToString()))
.ForMember(dest => dest.productDescription, act => act.MapFrom(src => src.product.title))
.ForMember(dest => dest.purchaseStatusDate, act => act.MapFrom(src => src.created_time))
.ForMember(dest => dest.quantity, act => act.MapFrom(src => src.count))
.ForMember(dest => dest.referenceId, act => act.MapFrom(src => src.reference_code))
.ForMember(dest => dest.totalPrice, act => act.MapFrom(src => src.total_customer_cost))
.ForMember(dest => dest.unitPrice, act => act.MapFrom(src => src.total_face_value))
.ForMember(dest => dest.currency, opt => opt.Ignore())
.ForMember(dest => dest.clientTrxRef, opt => opt.Ignore());
CreateMap<CardResponse, CouponDto>()
.ForMember(dest => dest.Pin, act => act.MapFrom(src => src.pin_code))
.ForMember(dest => dest.Serial, act => act.MapFrom(src => src.card_number))
.ForMember(dest => dest.expiryDate, opt => opt.Ignore());
CreateMap<List<Card>, List<GameConfirmResponseDto>>();
Any suggestions on how to manage?
Thanks in advance.