I have a .NET Web API and one of my API methods take a 'Status' param.
In my code, I have an enum (MyStatusEnum) with various status values, however, I don't want the user of our API to provide any of those values. Instead, I want them to provide a simpler status value, which ultimately gets mapped to one (or more) of our underlying status enum values.
For example, the user of my API must provide a status value of either 'InProgress' or 'Completed', but I would like model-binding to map 'InProgress' to an array of MyStatusEnum, where the values are considered to be 'InProgress', and likewise for 'Completed'.
public enum MyStatusEnum
{
StartedStepA = 1, // InProgress
StartedStepB = 2, // InProgress
StartedStepC = 3, // InProgress
FinishedStepA = 4, // Completed
FinishedStepB = 5, // Completed
FinishedStepC = 6 // Completed
}
public class ApiInputModel
{
public MyStatusEnum[] Status {get; set;}
}
So in this example, if they provided a status value of Completed, I'd want my model's MyStatsEnum (array) property to contain FinishedStepA, FinishedStepB & FinishedStepC.