I believe there is an error in the code in the Article.cs file in the BLL layer for the GetArticleCount(bool publishedOnly) method. The original method reads:
Code:
/// <summary>
/// Returns the number of total published articles
/// </summary>
public static int GetArticleCount(bool publishedOnly)
{
if (publishedOnly)
return GetArticleCount();
int articleCount = 0;
string key = "Articles_ArticleCount_" + publishedOnly.ToString();
if (BaseArticle.Settings.EnableCaching && BizObject.Cache[key] != null)
{
articleCount = (int)BizObject.Cache[key];
}
else
{
articleCount = SiteProvider.Articles.GetPublishedArticleCount(DateTime.Now);
BaseArticle.CacheData(key, articleCount);
}
return articleCount;
}
The problem I'm having is that when I pass in true to get the count for only published articles, its calling GetArticleCount, which returns the total number of articles, regardless of whether the article is published or not. If you pass in false, it does the exact opposite. I believe the code should read:
Code:
/// <summary>
/// Returns the number of total published articles
/// </summary>
public static int GetArticleCount(bool publishedOnly)
{
if (!publishedOnly)
return GetArticleCount();
int articleCount = 0;
string key = "Articles_ArticleCount_" + publishedOnly.ToString();
if (BaseArticle.Settings.EnableCaching && BizObject.Cache[key] != null)
{
articleCount = (int)BizObject.Cache[key];
}
else
{
articleCount = SiteProvider.Articles.GetPublishedArticleCount(DateTime.Now);
BaseArticle.CacheData(key, articleCount);
}
return articleCount;
}
The only change was made to the first if statement in the method. I simply inserted the NOT symbol to get the expected behavior.
Marco, can you verify that what I'm assuming is correct? Thanks and your book is awesome. Great job!
Douglas Rohm