Fixed several badge check conditions

  • 25 Views
  • Last Post 14 September 2017
siaonong posted this 11 September 2017

I just realised that 2 badges won't be applied correctly because their conditions are wrong. Don't know how to push my fixes on Github so I put them here below.

Badge.FavouriteFirstPostBadge.cs
public class FavouriteFirstPostBadge : IFavouriteBadge
{
 public bool Rule (MembershipUser user) {
  return user.Favourites.Count >= 1; // Should add = symbol
 }
}

Badge.UserVoteUpBadge.cs
public class UserVoteUpBadge : IVoteUpBadge
{
 public bool Rule (MembershipUser user) {
  return user.VotesGiven != null && user.VotesGiven.Count >= 1;   //Should be VotesGiven instead of Votes
 }
}

  • Liked by
  • pankajg1
  • YodasMyDad
Order By: Standard | Newest | Votes
YodasMyDad posted this 12 September 2017

Please create an issue on Github with the above code, it you are unable to do a pull request.

siaonong posted this 14 September 2017

Just done -> Github issue link

I will put some more code which fixed other badge issues I found in the same issue.

  • Liked by
  • YodasMyDad
siaonong posted this 14 September 2017

Users who mark his post as the solution to his own topic will be awarded "Your Question Solved" and "Post Selected As Answer" twice, as the attached picture below.

It's because the MarkAsSolution() of BadgeController will call badgeService.ProcessBadge() twice, once for the author of the topic (post.Topic.User), once for the author of the solution post (post.User). So the user will be awarded 2 badges as the author of the topic once and be awarded those 2 badges again as the author of the solution post.

I fixed this problem by adding an if statement in MarkAsSolution() of BadgeController as below:

if (post.User != post.Topic.User) {
 databaseUpdateNeeded = _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.User) | _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.Topic.User);
} else {
 databaseUpdateNeeded = _badgeService.ProcessBadge(BadgeType.MarkAsSolution, post.User);
}

Please ignore the Chinese characters because it didn't change back to English even I set the display language to the default en-GB language.

  • Liked by
  • YodasMyDad
Close