Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
Calling all developers! We invite you to provide your input on Feature Experimentation by completing this brief survey.
What Property Type is your ExpDate? A PropertyDate?
A good rule is not to use p.Property["PropertyName"].ToString() or p["PropertyName"].ToString() since they can be null if the property does not exist or the value can be null.
See http://world.episerver.com/Articles/Items/Best-Coding-Practices/. A good paranoia about this could be good.
Next I would have done something like this
pages = pages.OrderByDescending(p => ((DateTime) (p["ExpDate"] ?? DateTime.MinValue)) > DateTime.Now).ThenBy(p => p.PageName);
First you will order whether ExpDate is greater than current time is true or false, next by PageName.
At the moment I'm a little uncertain about if the correct implementation should be OrderBy/OrderByDescending and < or > with the datetime ordering but I hope this is a push in the right direction,
Perhaps this is more of a Linq question but it has to do with sorting a PageList so I give it a shot. The following line sorts by a date (ExpDate = Expiration Date) first presenting pages that hasn't expired (= date passed) and is the supposed to sort them from A-Z. Today being the 4th of June an example of this would be first pages A-Z with an ExpDate > 4th of June and then A-Z with an ExpDate < 4th of June.
I'm not that good at Linq and the problem with the following is that it only sorts the first part - the ones that has not yet expired - alphabetically and not the second part - the expired. Can anyone help me out and add what's missing so that they both sort from A-Z?
pages = pages.OrderByDescending(p => (DateTime.Parse(p.Property["ExpDate"].ToString()) < DateTime.Now) ? p.StartPublish.Date : DateTime.MaxValue).ThenBy(p => p.PageName);