/// <summary> /// Gets an IList with page of instances of ContentRating. /// </summary> public static List <ContentRating> GetPage(Guid contentGuid, int pageNumber, int pageSize, out int totalPages) { totalPages = 1; IDataReader reader = DBContentRating.GetPage(contentGuid, pageNumber, pageSize, out totalPages); return(LoadListFromReader(reader)); }
/// <summary> /// Updates this instance of ContentRating. Returns true on success. /// </summary> /// <returns>bool</returns> private bool Update() { return(DBContentRating.Update( this.rowGuid, this.emailAddress, this.rating, this.comments, this.ipAddress, this.lastModUtc)); }
public static ContentRatingStats GetStats(Guid contentGuid) { ContentRatingStats stats = new ContentRatingStats(); using (IDataReader reader = DBContentRating.GetStatsByContent(contentGuid)) { if (reader.Read()) { stats.TotalVotes = Convert.ToInt32(reader["TotalRatings"]); stats.AverageRating = Convert.ToInt32(reader["CurrentRating"]); } } return(stats); }
/// <summary> /// Persists a new instance of ContentRating. Returns true on success. /// </summary> /// <returns></returns> private bool Create() { this.rowGuid = Guid.NewGuid(); int rowsAffected = DBContentRating.Create( this.rowGuid, this.siteGuid, this.contentGuid, this.userGuid, this.emailAddress, this.rating, this.comments, this.ipAddress, this.createdUtc); return(rowsAffected > 0); }
public static void RateContent( Guid siteGuid, Guid contentGuid, Guid userGuid, int rating, string emailAddress, string comments, string ipAddress, int minutesBetweenAnonymousVotes ) { bool userHasRated = false; if (userGuid != Guid.Empty) { userHasRated = (DBContentRating.GetCountByContentAndUser(contentGuid, userGuid) > 0); } if (userHasRated) { ContentRating contentRating = new ContentRating(contentGuid, userGuid); contentRating.Rating = rating; if ((!string.IsNullOrEmpty(emailAddress)) && (contentRating.EmailAddress.Length == 0)) { contentRating.EmailAddress = emailAddress; } if ((!string.IsNullOrEmpty(comments)) && (contentRating.Comments.Length == 0)) { contentRating.Comments = comments; } contentRating.IpAddress = ipAddress; contentRating.Save(); } else { bool doRating = true; if (userGuid == Guid.Empty) { // if the anonymous user has rated this item from this ip address // within the last x minutes, don't let them vote again int countOfRatings = DBContentRating.GetCountOfRatingsSince( contentGuid, ipAddress, DateTime.UtcNow.AddMinutes(-minutesBetweenAnonymousVotes)); doRating = (countOfRatings == 0); } if (doRating) { DBContentRating.Create( Guid.NewGuid(), siteGuid, contentGuid, userGuid, emailAddress, rating, comments, ipAddress, DateTime.UtcNow); } } }
/// <summary> /// Deletes an instance of ContentRating. Returns true on success. /// </summary> /// <param name="rowGuid"> rowGuid </param> /// <returns>bool</returns> public static bool Delete(Guid rowGuid) { return(DBContentRating.Delete(rowGuid)); }
/// <summary> /// Gets an instance of ContentRating. /// </summary> private void GetContentRating(Guid contentGuid, Guid userGuid) { IDataReader reader = DBContentRating.GetOneByContentAndUser(contentGuid, userGuid); PopulateFromReader(reader); }
/// <summary> /// Gets an instance of ContentRating. /// </summary> /// <param name="rowGuid"> rowGuid </param> private void GetContentRating(Guid rowGuid) { IDataReader reader = DBContentRating.GetOne(rowGuid); PopulateFromReader(reader); }