The system has a page where the user can search for items by specifying a start date and an end date. These are simple dates (without a time component). For the user, it seems most intuitive for the end date to be included (so include all the elements for this end date as well).
CreateDate elements, however, contain a time component in the data warehouse. In practice, this means that we need to translate this perpetual end date to 0:00:00 oโclock the next day. Thus, we can write the following query:
SELECT * FROM Items WHERE CreateDate >= @STARTDATE AND CreateDate < @ENDDATE
Converting this end date is as simple as writing this line of code:
endDate.Date.AddDays(1);
Question:
should I consider this last line of code business logic and place it in the business layer, or should I consider this line as part of the "model binding logic" and should it be placed at the presentation level?
When it is placed in BL, it means that BL knows about the presentation layer, since the method of delivering the value is something specific to the interface. On the other hand, since the operation is defined as a DTO in the business layer, I could also see this object as an interface, which should be convenient for the presentation layer.
This question may even be philosophical in nature, since there are several ways to look at it, and the actual conversion code is trivial. I am interested to know why you think that it should be placed in one layer and not in another.
I do not expect the application architecture to influence the answer to this question. But to give a more complete picture, the architecture is based on commands and queries , and the presentation layer creates a query object that is processed by the business layer. PL code will usually look like this:
public Action Filter(DateTime start, DateTime end) { var query = new GetItemsByStartEndEndDateQuery { StartDate = start.Date, EndDate = end.Date.AddDays(1) } var items = this.queryProcessor.Handle(query); return this.View(items); }
Or, if possible, model binding (MVC) is used to simply model the binding of command and query objects (which is very convenient):
public Action Filter(GetItemsByStartEndEndDateQuery query) { var items = this.queryProcessor.Handle(query); return this.View(items); }
Will your answer change if there are multiple users (e.g. WCF layer and MVC layer)?