예제 #1
0
        ///// <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);
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByLastModUtc(ContentRating contentRating1, ContentRating contentRating2)
 {
     return(contentRating1.LastModUtc.CompareTo(contentRating2.LastModUtc));
 }
예제 #4
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByCreatedUtc(ContentRating contentRating1, ContentRating contentRating2)
 {
     return(contentRating1.CreatedUtc.CompareTo(contentRating2.CreatedUtc));
 }
예제 #5
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByIpAddress(ContentRating contentRating1, ContentRating contentRating2)
 {
     return(contentRating1.IpAddress.CompareTo(contentRating2.IpAddress));
 }
예제 #6
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByComments(ContentRating contentRating1, ContentRating contentRating2)
 {
     return(contentRating1.Comments.CompareTo(contentRating2.Comments));
 }
예제 #7
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByRating(ContentRating contentRating1, ContentRating contentRating2)
 {
     return(contentRating1.Rating.CompareTo(contentRating2.Rating));
 }