-1

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

Oak
  • 1,159
  • 3
  • 13
  • 21

1 Answers1

2

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

codingbiz
  • 26,179
  • 8
  • 59
  • 96
  • Hi, Thanks for the fast reply, i guess this answer is something that i wanted. Any prognosis how will it affect response time when there will be thousands of articles, each probably with 100+ "likes" and dates? – Oak Mar 29 '13 at 17:11
  • I don't think this should affect performance, but you should try this. This have been separated to different calls so you can call them for any date range you feel like or exempt those you don't want. And it only takes N records at a time – codingbiz Mar 29 '13 at 17:30
  • ok, sounds good for me than, thanks! – Oak Mar 29 '13 at 17:33