So I have a enumflag system and I need to filter by Narcotic, non-Narcotic, Psychotropic, and non-Psychotropic in a drop down list. My thinking was to put the values in dictionary and they viewbag into a selectlist on the front end, but I am having trouble configuring the dictionary to register "the absense of [var]"
If my dictionary is structured as thus:
private readonly Dictionary<int, string> _medicationDetails = new Dictionary<int, string>
{
{(int)PersonMedicationDescription.MedicationTags.NarcoticDrug, "Narcotic"},
{(int)PersonMedicationDescription.MedicationTags.PsychotropicDrug, "Psychotropic"}
};
I want to be able to do:
{(int)!PersonMedicationDescription.MedicationTags.NarcoticDrug, "non-Narcotic"},
or something along those lines. What am I missing here? Is there a better way to accomplish this?
EDIT:
Is a bool the right way to go. I know how to do that if it were just one bool, but how do I get both to populate the list? To get one to work I think this would work:
ViewBag.IsNarcoticOptions = new[]
{
true,
false
}.ToSelectList(b => b.ToString(), b => b.ToString("Narcotic", "Non Narcotic"));
var isNarcotic = filters.IsNarcotic;
if (isNarcotic.HasValue)
{
query = isNarcotic.Value
? query.Where(rdq => (rdq.MedicationFlags & (int)PersonMedicationDescription.MedicationTags.NarcoticDrug) == (int)PersonMedicationDescription.MedicationTags.NarcoticDrug)
: query.Where(rdq => (rdq.MedicationFlags & (int)PersonMedicationDescription.MedicationTags.NarcoticDrug) == 0);
}
but how to do that for another set of true/false?