how to create a list of top rated articles for a period of time? (asp.net c# ) [closed]

StackOverflow https://stackoverflow.com/questions/15707759

  •  30-03-2022
  •  | 
  •  

Question

i have a webpage that contains articles. Users are able to "Like" these articles. What i want to create is a list of top rated articles for each weeek/month, like "This weeks popular articles", "Last weeks popular articles" etc. I would like to know how to correctly implement this and calculate the votes so it will not slow the db/webpage later. Thanks, Oak

Was it helpful?

Solution

You can create a function that accepts 3 parameters

public List<Aritcle> GetTopArticles(int top, DateTime startDate, DateTime endDate)
{
   //Implement this method 
   //e.g.
   //Select Top(10) * From Article 
   //Where likeDate Between startDate AND endDate
   //ORDER BY Likes DESC
}

You can now call this method several times based on the date you want e.g. This week, last week, last month

var topArticlesThisWeek = GetTopArticles(10, DateTime.Parse('2013-03-24'), DateTime.Today);
var topArticlesLastMonth = GetTopArticles(10, DateTime.Parse('2013-02-01'), DateTime.Parse('2013-02-29'));

But those days have to be dynamic - not as hard-coded as I did

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top