I have a problem with litle. Iām a new developer, and I have an age criteria view for my product.
These parameters are: "<24", "24-35", "35-45", "> 45".
The json I need to work looks like this:
"age": { "lessThan24": true, "between24And35": true, "between35And45": true, "moreThan45": true }
My View Model:
public class AgeCriterionViewModel { public bool? LessThan24 { get; set; } public bool? Between24And35 { get; set; } public bool? Between35And45 { get; set; } public bool? MoreThan45 { get; set; } }
And my domain model:
public class AgeCriterion { public int? From { get; set; } public int? To { get; set; } }
So here is my problem. I need to map the viewmodel to the domain model. But these booleans are NULL, so they can be null, false, or true. OLSO can be multi-selective. Thus, these parameters can be "lessthan24" and "between35and45" or all of them or none.
I'm thinking of creating some kind of awful BIG IF construct. But how can I check all the parameters? Is there a good way?
I have that at the moment:
if (age == null) return null; AgeCriterion criterion = new AgeCriterion(); if (age.LessThan24.HasValue) { if (age.LessThan24.Value) { criterion.From = 0; criterion.To = 24; } }
source share