コード例 #1
0
        public static int GetPropertyStarRating(Property theProperty)
        {
            try
            {
                var comments = Comment.GetComments(theProperty).ToList();
                var thisPropertysNumberOfComments = //call methods to pull back commments
                                                    comments.Count;
                var sumOfComments = 0;

                foreach (var comment in comments)
                {
                    sumOfComments += comment.StarRating ?? 0;
                }

                var propertyOverallRating = sumOfComments / thisPropertysNumberOfComments;


                return((int)propertyOverallRating);
            }
            catch (DivideByZeroException dbzException)
            {
                return(0);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }