///// <summary> ///// Gets a count of ContentRating. ///// </summary> //public static int GetCountByContent(Guid contentGuid) //{ // return DBContentRating.GetCountByContent(contentGuid); //} private static List <ContentRating> LoadListFromReader(IDataReader reader) { List <ContentRating> contentRatingList = new List <ContentRating>(); try { while (reader.Read()) { ContentRating contentRating = new ContentRating(); contentRating.rowGuid = new Guid(reader["RowGuid"].ToString()); contentRating.siteGuid = new Guid(reader["SiteGuid"].ToString()); contentRating.contentGuid = new Guid(reader["ContentGuid"].ToString()); contentRating.userGuid = new Guid(reader["UserGuid"].ToString()); contentRating.emailAddress = reader["EmailAddress"].ToString(); contentRating.rating = Convert.ToInt32(reader["Rating"]); contentRating.comments = reader["Comments"].ToString(); contentRating.ipAddress = reader["IpAddress"].ToString(); contentRating.createdUtc = Convert.ToDateTime(reader["CreatedUtc"]); contentRating.lastModUtc = Convert.ToDateTime(reader["LastModUtc"]); contentRatingList.Add(contentRating); } } finally { reader.Close(); } return(contentRatingList); }
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> /// Compares 2 instances of ContentRating. /// </summary> public static int CompareByLastModUtc(ContentRating contentRating1, ContentRating contentRating2) { return(contentRating1.LastModUtc.CompareTo(contentRating2.LastModUtc)); }
/// <summary> /// Compares 2 instances of ContentRating. /// </summary> public static int CompareByCreatedUtc(ContentRating contentRating1, ContentRating contentRating2) { return(contentRating1.CreatedUtc.CompareTo(contentRating2.CreatedUtc)); }
/// <summary> /// Compares 2 instances of ContentRating. /// </summary> public static int CompareByIpAddress(ContentRating contentRating1, ContentRating contentRating2) { return(contentRating1.IpAddress.CompareTo(contentRating2.IpAddress)); }
/// <summary> /// Compares 2 instances of ContentRating. /// </summary> public static int CompareByComments(ContentRating contentRating1, ContentRating contentRating2) { return(contentRating1.Comments.CompareTo(contentRating2.Comments)); }
/// <summary> /// Compares 2 instances of ContentRating. /// </summary> public static int CompareByRating(ContentRating contentRating1, ContentRating contentRating2) { return(contentRating1.Rating.CompareTo(contentRating2.Rating)); }