public bool AddRating(long userid, string url, double value) { var user = _userService.GetUserById(userid); if (user != null) { return(false); } if (!HasUserRated(userid, url)) { var subDirectory = _subDirectoryService.FindOrInsertSite(url); var rate = GetRatingBySubDirectoryId(subDirectory.Id); if (rate == null) { _ratingRepository.Add(new Rating() { RatingValue = value, SubDirectoryId = subDirectory.Id }); _userRatingService.AddUserRating(userid, rate.Id, value); } else { UpdateRating(rate.Id, value); } //set user stat _userService.CalculateAndUpdateUserRatingStatistics(user.Id); return(true); } return(false); }
public Comment AddComment(string url, string content, long creatorId, long?parentId) { var creator = _userService.GetUserById(creatorId); if (creator != null) { //Get all the info needed for the insertion var subDirectory = _subDirectoryService.FindOrInsertSite(url); var contentObj = _contentService.AddContent(subDirectory.Id, ContentTypeMap.Comment); var parentComment = (Comment)null; if (parentId.HasValue) { parentComment = GetCommentById(parentId.Value); } //Add the comment var comment = new Comment() { Upvotes = 0, Sitename = subDirectory.Site?.Name, Content = content, CreatedAt = DateTime.Now, ContentId = contentObj.Id, CreatorId = creatorId, CreatedByAdmin = false, ModifiedAt = DateTime.Now, ParentId = parentComment != null ? parentId : null, ProfilePictureUrl = creator.ProfilePictureUrl, Pings = 0 }; _commentRepository.Add(comment); var saved = Convert.ToBoolean(_commentRepository.Save()); if (saved) { return(comment); } } return(null); }