I am building a custom CMS in ASP.NET MVC and one of the requirements is that the content has a start and end date that dictates whether or not the page appears on the site. What is the best approach to this? Should I run some sort of chron job to mark the status of the page according to its publish dates? Does anyone have any resources or advice on the matter?
Asked
Active
Viewed 138 times
2 Answers
1
Why not just do something like this
bool visible = true;
if (startdate > now || enddate < now)
visible = false;
That way you don't have to have another process.

Daniel A. White
- 187,200
- 47
- 362
- 445
-
Or even: bool visible = startdate < now && now < enddate; – Matthew Scharley Sep 22 '09 at 13:59
0
You seem eager to make model responsible for choosing active items.
Depending on the size (count) of the items you query, to preserve response time.
if you have many items, you better use a windows service to mark active items.
also you can index the column you use to mark active items.
alternatively, you can make the View responsible for displaying or hiding the item
foreach(var item in Model)
if(Item.DisplayAllowed) renderpartial("ItemView",item);

Ahmed Khalaf
- 1,220
- 12
- 28
-
2Having a windows service could potential solve scaling problems as you point out. But I would be quite hesitant to putting conditional logic in the View. The MVC purists amongst us would strongly argue that there should be no logic in the View, the data that you present to your view should already be correctly filtered. – Gavin Osborn Sep 22 '09 at 13:48
-
I agree with you osborn, but I do anti-pattern if the pattern becomes non feasible... in addition view is responsible of handling presentation, and this issue somehow is. (seems we are in the gray area :D) – Ahmed Khalaf Sep 22 '09 at 15:41