Context:
Recently, I worked on a requirement that required a list of job schedules to be sorted according to priorities imposed on the value of a property of the job schedule, on a ASP.NET MVC view of a web app. I can put the logic that sorts the data anywhere in the stack to meet this particular requirement. I could put the sorting logic in the SQL query, or in the repository method after getting the data, or I can sort the data at the controller level before feeding to it to the view that renders it. The SQL query and the repository method are used by other code that doesn’t need the data sorted so I’d be adding undue burden to other code when the data doesn’t need to be sorted. I decided to sort the data at the controller level. This is a trieval design decision but I think this thought process is important to ensure the scalability of your application architecture.
The Requirement:
Given the schedule priority with the following values:
“A” : AM
“P” : PM
“O” : Any time
“F” : First
the schedule list should be sorted in the following order:
-
“F” : First
-
“A” : AM
-
“O” : Any time
-
“P” : PM
As you can see from the data I cannot sort the list using the values’ alphabetical order. That means I need to create a custom comparer to be used to the value in this manner.
“F” : First
“A” : AM
“O” : Any time
“P” : PM
No comments:
Post a Comment