I am trying to organize many different request forms into objects.
I am a little too novice to understand how to orient the objects but I kind of understand the behavior I want.
for example
public class RequestForm
{
public string Name {get;set;}
public DateTime CreateDate {get;set;}
public void Submit()
{
}
}
public class PTORequestForm : RequestForm
{
public DateTime StartDate {get;set;}
public DateTime EndDate {get;set;}
public void Submit()
{
do x
}
}
public class ChangeDeptRequestForm : RequestForm
{
public string NewDeptName {get;set;}
public void Submit()
{
do y
}
}
All implements save to the database a record that has a discriminator and a field for the request converted to JSON
Everything seemed fine so far in my developing this and I started to wonder how I display the information.
I'm working in blazor so I have a component that renders the db model and then another component inside it that loads the deserialized request.
private RequestForm request {get;set;}
public override task OnInitializeAsync()
{
request = JsonSerializer.Deserialize<PTORequestForm>(jsonData)
}
I'm not able to then do
<span>@request.StartDate</span>
What patterns should I look at or what am I doing wrong or missing preventing me from displaying the information correctly? Or do I need to make a .razor for every request type instead of something generic enough to handle the different child objects?