views:

63

answers:

2

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?

A: 

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
Or even: bool visible = startdate < now
Matthew Scharley
this is not the tricky part of the job :)
Ahmed Khalaf
A: 

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
Having 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
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