c# - How to program with an age (or any other) range -


i trying create maintenance page admin create/amend/delete age ranges show on page customer select age range.

age range

1-20, 21-40, 41-60, 61-80, 81-100 

allow values amended , deleted range cannot overlap or exist in first place

so based on above below entries cannot exist

2-30 - falls within range or 22- 30 - falls within range etc etc 

so far have code check if range exists

ienumerable<agerange> ar = in mydatacontext.ageranges.where(aa => aa.minage <= newage.minage && aa.maxage >= newage.minage) select a; 

not tested far seems trick. added in delete function. if delete range 41-60 have new set of issues.

if add new entry 42 - 59 customer cannot select range if age 41 or 60 above code not find above range allow save. amended range in example be

1-20 21-40 - customer 41 cant select option 42-59 - customer 41 cant select option either. if customer 60 cant select option 61-80 - if customer 60 cant select option either. 81-100 

i think have similar issues when updating existing range.

is there easy way or appropriate control use or other ideas?

thanks

one possibility may have single "maximum age" field. check range existing becomes simpler:

ienumerable<agerange> ar = in mydatacontext.ageranges              .where(aa => aa.maximimage != newage.maximumage) select a; 

you have no need worry leaving gap between ranges (as automatically filled).

the issue you're left within ui, rendering list of " min - max" values. however, should relatively simple write few lines of code could, given agerange, finds maximum age of "next lowest" agerange, adds 1 , counts minimum of current one.


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -