I have a base class Ad
.
public class Ad
{
public int Id{get;set;}
public string Title{get;set;}
public string Price{get;set;}
}
Then I have a lot of derived classes like:
public class CarAd : Ad
{
public string ModelName {get;set;}
}
public class MobileAd : Ad
{
public string CompanyName {get;set;}
}
And accordingly I have ViewModels for these classes as well.
public class AdViewModel
{
public int Id{get;set;}
public string Title{get;set;}
public string Price{get;set;}
}
public class CarAdViewModel : AdViewModel
{
public string ModelName {get;set;}
}
public class MobileAdViewModel : AdViewModel
{
public string CompanyName {get;set;}
}
I am trying to map derived class with base class using value injecter. Like:
[HttpPost]
public async Task<IHttpActionResult> Post([FromBody] CarAdViewModel carAdModel)
{
var ad = new Ad();
ad.InjectFrom(carAdModel);
}
But it is not mapping properties of derived class. Can somebody tell me if it is possible?