How to implement icons?

I thought about implementing the icons (like the icons here in Stack Overflow), and thinking that it would be difficult without Windows services, but I would like to avoid this if possible.

I came up with a plan to implement some examples:

  • Audobiographer: check if all fields in the profile are filled.
  • Comment: when commenting, check if the number of comments is equal to 10 if this is the way the icon is awarded.
  • Good answer: when voting, check to see if the vote rating is 25 or higher.

How can this be implemented in a database? Or maybe better?

+42
c # sql-server-2005 asp.net-mvc-2 badge
Jul 01 2018-10-01T00:
source share
4 answers

Implementing a similar type of -Stackoverflow is actually much simpler than you described, based on a bit of information that the command discarded every time after a while.

In the database, you simply save a collection of BadgeID - UserID to track who has it (and a counter or rowID to allow multiple rewards for some badges).

The application has a work object for each type of icon. The object is in the cache, and when the cache expires, the worker runs his own logic to determine who should receive the icon and make updates, and then he inserts himself into the cache again:

 public abstract class BadgeJob { protected BadgeJob() { //start cycling on initialization Insert(); } //override to provide specific badge logic protected abstract void AwardBadges(); //how long to wait between iterations protected abstract TimeSpan Interval { get; } private void Callback(string key, object value, CacheItemRemovedReason reason) { if (reason == CacheItemRemovedReason.Expired) { this.AwardBadges(); this.Insert(); } } private void Insert() { HttpRuntime.Cache.Add(this.GetType().ToString(), this, null, Cache.NoAbsoluteExpiration, this.Interval, CacheItemPriority.Normal, this.Callback); } } 

And specific implementation:

 public class CommenterBadge : BadgeJob { public CommenterBadge() : base() { } protected override void AwardBadges() { //select all users who have more than x comments //and dont have the commenter badge //add badges } //run every 10 minutes protected override TimeSpan Interval { get { return new TimeSpan(0,10,0); } } } 
+41
Jul 01 '10 at 23:52
source share

Work. This is the key. Outside of work assignments that run at set intervals to check the criteria you mentioned. I do not think that you even need to have a Windows service if you do not need external resources to install it. I really think that StackOverflow also uses jobs for its calculations.

+4
Jul 01 '10 at 23:50
source share

You can use triggers and check for updates or insert, and then, if your conditions are met, add an icon. Something that does this seems to be less. Trigger start at 3, 2, 1 ...

0
Jul 01 '10 at 23:51 on
source share

Comments must be stored in the database correctly? then I think there are two main ways to do this.

1) when the user logs in, you get the number of comments. this is clearly not a desirable approach, as the bill can take a long time

2) when the user submits a comment, you can either perform a count, or save the counter using data, or execute a trigger that is executed when a comment is added. the trigger will then receive the details of the newly created comment, capture the user ID, get a counter and save it against the user in any table.

I like the idea of ​​a trigger, as your program may return without waiting for the sql server to do its best.

0
Jul 01 '10 at 23:52
source share



All Articles