Example #1
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public PostModel()
 {
     Attachments = new List <Media>();
     Categories  = new List <Category>();
     Comments    = new List <CommentModel>();
     Ratings     = new RatingsModel();
 }
Example #2
0
        /// <summary>
        /// Gets the ratings model for the specified model.
        /// </summary>
        /// <param name="api">The current api</param>
        /// <param name="id">The model id</param>
        /// <returns>The available ratings</returns>
        public static RatingsModel GetByModelId(Api api, Guid id)
        {
            var ratings = api.Ratings.Get(where : r => r.ModelId == id);
            var model   = new RatingsModel();

            foreach (var rating in ratings)
            {
                if (rating.Type == RatingType.Star)
                {
                    model.Stars.Add(new RatingsItem()
                    {
                        UserId = rating.UserId
                    });
                }
                else if (rating.Type == RatingType.Like)
                {
                    model.Likes.Add(new RatingsItem()
                    {
                        UserId = rating.UserId
                    });
                }
                else if (rating.Type == RatingType.Dislike)
                {
                    model.Dislikes.Add(new RatingsItem()
                    {
                        UserId = rating.UserId
                    });
                }
            }
            return(model);
        }
Example #3
0
 /// <summary>
 /// Loads all available ratings for the current page.
 /// </summary>
 public virtual PageModel WithRatings()
 {
     // Get all ratings
     using (var api = new Api()) {
         Ratings = RatingsModel.GetByModelId(api, Id);
     }
     return(this);
 }
Example #4
0
 /// <summary>
 /// Loads all available ratings for the posts in the archive.
 /// </summary>
 public virtual ArchiveModel WithRatings()
 {
     // Get all ratings
     using (var api = new Api()) {
         foreach (var post in Posts)
         {
             post.Ratings = RatingsModel.GetByModelId(api, post.Id);
         }
     }
     return(this);
 }
Example #5
0
		/// <summary>
		/// Gets the ratings model for the specified model.
		/// </summary>
		/// <param name="api">The current api</param>
		/// <param name="id">The model id</param>
		/// <returns>The available ratings</returns>
		public static RatingsModel GetByModelId(Api api, Guid id) {
			var ratings = api.Ratings.Get(where: r => r.ModelId == id);
			var model = new RatingsModel();

			foreach (var rating in ratings) {
				if (rating.Type == RatingType.Star)
					model.Stars.Add(new RatingsItem() { UserId = rating.UserId });
				else if (rating.Type == RatingType.Like)
					model.Likes.Add(new RatingsItem() { UserId = rating.UserId });
				else if (rating.Type == RatingType.Dislike)
					model.Dislikes.Add(new RatingsItem() { UserId = rating.UserId });
			}
			return model;
		}
Example #6
0
        /// <summary>
        /// Loads all available comments for the current post.
        /// </summary>
        /// <param name="ratings">If ratings should be included</param>
        public virtual PostModel WithComments(bool ratings = false)
        {
            // Get all comments
            using (var api = new Api()) {
                Comments = Mapper.Map <IEnumerable <Comment>, IEnumerable <CommentModel> >(api.Comments.Get(where : c => c.PostId == Id)).ToList();

                if (ratings)
                {
                    foreach (var comment in Comments)
                    {
                        comment.Ratings = RatingsModel.GetByModelId(api, comment.Id);
                    }
                }
            }
            return(this);
        }
Example #7
0
 /// <summary>
 /// Default constructor.
 /// </summary>
 public PageModel()
 {
     Ratings = new RatingsModel();
 }