Beispiel #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>();

            using (reader)
            {
                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);
                }
            }

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

                }
            }

            return contentRatingList;
        }
Beispiel #10
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByRating(ContentRating contentRating1, ContentRating contentRating2)
 {
     return contentRating1.Rating.CompareTo(contentRating2.Rating);
 }
Beispiel #11
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByLastModUtc(ContentRating contentRating1, ContentRating contentRating2)
 {
     return contentRating1.LastModUtc.CompareTo(contentRating2.LastModUtc);
 }
Beispiel #12
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByIpAddress(ContentRating contentRating1, ContentRating contentRating2)
 {
     return contentRating1.IpAddress.CompareTo(contentRating2.IpAddress);
 }
Beispiel #13
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByCreatedUtc(ContentRating contentRating1, ContentRating contentRating2)
 {
     return contentRating1.CreatedUtc.CompareTo(contentRating2.CreatedUtc);
 }
Beispiel #14
0
 /// <summary>
 /// Compares 2 instances of ContentRating.
 /// </summary>
 public static int CompareByComments(ContentRating contentRating1, ContentRating contentRating2)
 {
     return contentRating1.Comments.CompareTo(contentRating2.Comments);
 }