I have an existing asp.net core razor page that records events for our Security Team. They would like to record Lost and Found events as well, but have them kept separate from the Security events. I would like to reuse the same database table and differentiate the record (AppType). Although the two apps share many similarities, Lost and Found does not use all of the same properties (i.e. L&F will not use SubjectDOB but it is required in the Security model. This will cause (!ModelState.IsValid) to return false. What is the best way to reuse the SecurityLog model for Lost and Found for only the properties that I need? Perhaps I need to split the classes up?
public class SecurityLog
{
public string AppType { get; set; }
[Required]
[Display(Name = "Subject's First Name")]
public string SubjectFirst { get; set; }
[Required]
[Display(Name = "Subject's Last Name")]
public string SubjectLast { get; set; }
[Required]
[Display(Name = "Subject's B#/DOB")]
public string SubjectDOB { get; set; }
[Display(Name = "Entered By")]
public string EnteredBy { get; set; }
etc...
}
I've tried removing subjectDOB from the model but this does not work b/c it is required.
public async Task<IActionResult> OnPostAsync()
{
ModelState.Remove("SubjectDOB");
if (!ModelState.IsValid)
{
return Page();
}
}