I have a few web sites and load articles on the main page. I can set ranking on the articles to display them in different order but the ordering could be different on the various sites for the articles.
The code I have to order the articles sets the same order for all sites:
string officeLocation = "";
// office location could be either World, Europe, Africa, America, Asia, Pacific
var result = articles.Select(a => new
{
Title = a.Title,
Url = a[SPBuiltInFieldId.FileRef],
Byline = a[Constants.FieldNames.Byline],
ArticleDate = a[Constants.FieldNames.ArticleStartDate],
RankWorld = a[Constants.FieldNames.World],
RankEurope = a[Constants.FieldNames.RankEurope],
RankAfrica = a[Constants.FieldNames.RankAfrica],
RankAmerica = a[Constants.FieldNames.RankAmerica],
RankAsia = a[Constants.FieldNames.RankAsia],
RankPacific = a[Constants.FieldNames.RankPacific],
});
rptArticles.DataSource = result.OrderBy(a => a.RankWorld);
rptArticles.DataBind();
The code sets all ranking to whatever RankWorld is (1-6).
If the string officeLocation (that is passed on to the method) is Europe then I want to order by a.RankEurope, if officeLocation is Asia order by a.RankAsia and so on.
How can I best achieve this (.NET 3.5)?
Thanks in advance.
Assuming you have a fixed set of locations (which by definition, you must have as you’re stating them in the anonymous type) then you could just use a switch:
Obviously, you need to decide how best to handle an unexpected location.
Note that, ideally, I would have just assigned the
OrderByfunction to aFunc<T,R>, but and only have oneOrderBycall, but you can’t do that here due to the anonymous type.