Razi Rais
All writing
October 25, 2005 1 min read

MCMS Restrict Posting only during 9am to 5pm

Check out the follwoing code sample , it shows how to allow posting in MCMS2002 only during 9am to 5pm

this is a classic example of how bussiness rules can be applied.

protected void CmsPosting_Submitted( Object sender, ChangedEventArgs e )

{

//get the posting

Posting post = e.Target

as Posting;

//Get the current time of server

String now = DateTime.Now.ToShortTimeString();

String []hr = now.Split(‘:’);

String []min = hr[1].Split(‘ ‘);

String amPm = min[1];

Int32 allowedStartHour = 9;

Int32 allowedEndHour = 5;

String allowedZone = “am”;

if(“am”.Equals(amPm.ToLower()))

{

//check for 9 – 12 am (12 pm exclusive)

if(Int32.Parse(hr[0]) >= allowedStartHour && Int32.Parse(hr[0])<=11)

{

//allowed

Response.Write(“The Posting is submitted sucessfully”);

}

else

{

//delete

Response.Write(“The Posting can only submitted at 9am to 5pm ”);

CmsHttpContext.Current.CommitAll();

post.AcquireOwnership();

post.Delete();

CmsHttpContext.Current.CommitAll();

Response.Redirect(“http://localhost/MCMS/McmsHomeport/McmsHomeport.aspx&quot;);

}

}

else if(“pm”.Equals(amPm.ToLower()))

{

//check for 12 – 5 pm

if(Int32.Parse(hr[0])>= 12 && Int32.Parse(hr[0])<=allowedEndHour-1)

{

//allowed

Response.Write(“The Posting is submitted sucessfully”);

}

else

{

Response.Write(“The Posting can only submitted at 9am to 5pm ”);

CmsHttpContext.Current.CommitAll();

post.AcquireOwnership();

post.Delete();

CmsHttpContext.Current.CommitAll();

Response.Redirect(“http://localhost/MCMS/McmsHomeport/McmsHomeport.aspx&quot;);

}

}//end conditional logic

 }

The only thing required is an HHTP CMSPosting Mudule , enrolled in web.config.


Originally published on WordPress on 2005-10-25.


Worth reading again?

Get the next one in your inbox.

No noise. Whenever something's worth saying.

Unsubscribe any time. No marketing, no noise.