/// <summary> /// /// </summary> /// <param name="currentInfo"></param> /// <param name="post"></param> /// <param name="rating"></param> /// <returns></returns> public static ModuleRatingInfo addRating(ModuleRatingInfo currentInfo, Post post, Rating rating) { // If post is not null, add the post and rating to forums database. // Even if the post is empty, still add it. if (post != null) { post.PostType = Posts.PostType.Rating; post.ParentID = currentInfo.ThreadID; post.IsLocked = true; post = Posts.AddPost(post); rating.PostID = post.PostID; Ratings.AddRating(rating); } // Calculate the new rating and construct a new ModuleRatingInfo // object to be returned. float newRating = 0; if (currentInfo.NumRatings == 0) { newRating = rating.Value; } else { newRating = (currentInfo.Rating * currentInfo.NumRatings + rating.Value) / (currentInfo.NumRatings + 1); } ModuleRatingInfo newInfo = new ModuleRatingInfo(); newInfo.ModuleID = currentInfo.ModuleID; newInfo.ThreadID = currentInfo.ThreadID; newInfo.Rating = newRating; newInfo.NumRatings = currentInfo.NumRatings + 1; // Update the module rating in the module database. ModuleRatings.updateRating(newInfo); return(newInfo); }