/// <summary> /// Mark a topic as solved /// </summary> /// <param name="topic"></param> /// <param name="post"></param> /// <param name="marker"></param> /// <param name="solutionWriter"></param> /// <param name="memberPointsService"></param> /// <returns>True if topic has been marked as solved</returns> public bool SolveTopic(Topic topic, Post post, Member marker, Member solutionWriter, MemberPointsService memberPointsService) { var solved = false; // Make sure this user owns the topic, if not do nothing if (topic.MemberId == marker.Id) { // Update the post post.IsSolution = true; // Update the topic topic.Solved = true; // Assign points // Do not give points to the user if they are marking their own post as the solution if (marker.Id != solutionWriter.Id) { memberPointsService.Add(new MemberPoints { Points = Dialogue.Settings().PointsAddedForASolution, Member = solutionWriter, MemberId = solutionWriter.Id, RelatedPostId = post.Id }); } solved = true; } return(solved); }
/// <summary> /// Add a new post /// </summary> /// <param name="postContent"> </param> /// <param name="topic"> </param> /// <param name="user"></param> /// <param name="permissionService"></param> /// <param name="categoryPermissionService"></param> /// <param name="memberPointsService"></param> /// <param name="permissions"> </param> /// <param name="memberService"></param> /// <returns>True if post added</returns> public Post AddNewPost(string postContent, Topic topic, Member user, PermissionService permissionService, MemberService memberService, CategoryPermissionService categoryPermissionService, MemberPointsService memberPointsService, out PermissionSet permissions) { // Get the permissions for the category that this topic is in permissions = permissionService.GetPermissions(topic.Category, user.Groups.FirstOrDefault(), memberService, categoryPermissionService); // Check this users role has permission to create a post if (permissions[AppConstants.PermissionDenyAccess].IsTicked || permissions[AppConstants.PermissionReadOnly].IsTicked) { // Throw exception so Ajax caller picks it up throw new ApplicationException(AppHelpers.Lang("Errors.NoPermission")); } // Has permission so create the post var newPost = new Post { PostContent = postContent, Member = user, MemberId = user.Id, Topic = topic, IpAddress = AppHelpers.GetUsersIpAddress(), DateCreated = DateTime.UtcNow, DateEdited = DateTime.UtcNow }; newPost = SanitizePost(newPost); var category = topic.Category; if (category.ModerateAllPostsInThisCategory == true) { newPost.Pending = true; } // create the post Add(newPost); // Update the users points score and post count for posting memberPointsService.Add(new MemberPoints { Points = Dialogue.Settings().PointsAddedPerNewPost, MemberId = user.Id, RelatedPostId = newPost.Id }); // add the last post to the topic topic.LastPost = newPost; // Add post to members count memberService.AddPostCount(user); return(newPost); }
/// <summary> /// Processes the user for the specified badge type /// </summary> /// <param name="badgeType"></param> /// <param name="user"></param> /// <param name="memberPointsService"></param> /// <param name="activityService"></param> /// <returns>True if badge was awarded</returns> public bool ProcessBadge(BadgeType badgeType, Member user, MemberPointsService memberPointsService, ActivityService activityService) { var databaseUpdateNeeded = false; if (_badges.ContainsKey(badgeType)) { if (!RecentlyProcessed(badgeType, user)) { databaseUpdateNeeded = true; var badgeSet = _badges[badgeType]; foreach (var badgeMapping in badgeSet) { if (!BadgeCanBeAwarded(user, badgeMapping)) { continue; } // Instantiate the badge and execute the rule var badge = GetInstance <IBadge>(badgeMapping); // Award badge? if (badge != null && badge.Rule(user)) { // Re-fetch the badge otherwise system will try and create new badges! var dbBadge = GetallBadges().FirstOrDefault(x => x.Id == badgeMapping.DbBadge.Id); if (dbBadge != null) { if (dbBadge.AwardsPoints != null && dbBadge.AwardsPoints > 0) { var points = new MemberPoints { DateAdded = DateTime.UtcNow, Points = (int)dbBadge.AwardsPoints, MemberId = user.Id }; memberPointsService.Add(points); } var exists = ContextPerRequest.Db.BadgeToMember .FirstOrDefault(x => x.DialogueBadgeId == dbBadge.Id && x.MemberId == user.Id); if (exists == null) { // Add the badge mapping var badgeMember = new BadgeToMember { DialogueBadgeId = dbBadge.Id, MemberId = user.Id }; ContextPerRequest.Db.BadgeToMember.Add(badgeMember); // This needs to be //ContextPerRequest.Db.Badge.Add(dbBadge); activityService.BadgeAwarded(badgeMapping.DbBadge, user, DateTime.UtcNow); } } } } } } return(databaseUpdateNeeded); }