How to return an enum ID instead of the enum text in WebAPI
- by Rodney
I am using the WebAPI with .NET 4.5. I have a enum called DareStatus which is a list of statuses and their corresponding integer ID's. To minimize bandwidth traffic I want to send the int values of the enums, not the full text as it is currently doing. (I have control over the client so I can map it on the clientside). The strange thing is that in my RTFM-ing everyone seems to have the opposite issue!
http://www.ftter.com/desktopmodules/framework/api/dare/getalldares
public enum DareStatus : int
{
All = 0,
Accepted = 2,
Pending = 1,
Declined = 3,
Cancelled = 4,
Failed = 5,
Won = 6
}
public IEnumerable<DareInfo> GetDares()
{
IEnumerable<DareInfo> dareInfos;
using (IDataContext ctx = DataContext.Instance())
{
var rep = ctx.GetRepository<DareInfo>();
dareInfos = rep.Get();
}
return dareInfos;
}