Esempio n. 1
0
        /// <summary>
        /// Inser the comment and record on user time line
        /// </summary>
        /// <param name="userComment"></param>
        /// <returns></returns>
        public IUserComment PostUserComment(IUserComment userComment)
        {
            // Post the comment
            userComment = repository.Save(userComment);

            // Record on time line
            repository.Save(new TimeLine(userComment.UserId, TimeLineEntry.Comment, userComment.MemeId, userComment.Id, null, null));

            // Update the number of comments added by this user
            IUser user = repository.GetUser(userComment.UserId);

            if (user != null)
            {
                user.Comments++;

                // Save commentator
                repository.Save(user);
            }

            // Update the number of comments on the meme
            IMeme meme = repository.GetMeme(userComment.MemeId);

            if (meme != null)
            {
                meme.UserCommentCount++;

                // Save comment count
                memeBusiness.Save(meme);
            }
            return(userComment);
        }
Esempio n. 2
0
        /// <summary>
        /// Gets the timeline entry model from an idividual timeline enrty.
        /// </summary>
        /// <param name="entry">The entry.</param>
        /// <returns></returns>
        private TimelineEntryModel GetTimelineEntryModel(ITimeLine entry)
        {
            TimelineEntryModel timelineEntryModel = new TimelineEntryModel(entry);

            timelineEntryModel.User = repository.GetUser(entry.UserId);

            // Get the meme referenced by the time line entry
            timelineEntryModel.Meme = new MemeLiteModel(repository, repository.GetMeme(entry.TimeLineRefId));

            // Resolve the comment
            if (entry.EntryType == TimeLineEntry.Comment ||
                entry.EntryType == TimeLineEntry.LikeComment ||
                entry.EntryType == TimeLineEntry.DislikeComment)
            {
                IUserComment userComment = repository.GetUserComment(entry.TimeLineRefAlternateId);
                userComment.Comment = WebUtility.HtmlEncode(userComment.Comment);
                IUser user = userComment.UserId != null?repository.GetUser(userComment.UserId) : new Domain.User();

                timelineEntryModel.UserComment = new TimeLineUserCommentModel(userComment, user);
            }

            // Resolve the alternative ref id (always a meme)
            if (entry.EntryType == TimeLineEntry.Reply)
            {
                timelineEntryModel.AlternateMeme = new MemeLiteModel(repository, repository.GetMeme(entry.TimeLineRefAlternateId));
            }
            return(timelineEntryModel);
        }
Esempio n. 3
0
 public TimeLineUserCommentModel(IUserComment userComment, IUser user)
 {
     this.Id          = userComment.Id;
     this.MemeId      = userComment.MemeId;
     this.UserId      = userComment.UserId;
     this.UserName    = userComment.UserName;
     this.DateCreated = userComment.DateCreated;
     this.Likes       = userComment.Likes;
     this.Dislikes    = userComment.Dislikes;
     this.Comment     = WebUtility.HtmlEncode(userComment.Comment);
     this.User        = user;
 }
Esempio n. 4
0
        public HttpResponseMessage LikeComment(string id)
        {
            string userId = User.Identity.UserId();

            // Record the like of the comment
            IUserComment userComment = userCommentBusiness.LikeComment(id, userId);

            if (userComment == null)
            {
                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound));
            }

            var response = Request.CreateResponse(HttpStatusCode.Created, userComment);

            response.Headers.Location = new Uri(Request.RequestUri, "/api/comments/" + userComment.Id);
            return(response);
        }
Esempio n. 5
0
        /// <summary>
        /// Record the like of a user comment on the comment and in the time line
        /// </summary>
        /// <param name="userCommentId"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public IUserComment LikeComment(string userCommentId, string userId)
        {
            IUserComment userComment = repository.GetUserComment(userCommentId);

            if (userComment == null)
            {
                return(null);
            }

            // Increment the likes of the comment
            userComment.Likes++;

            // Record on the user comment
            userComment = repository.Save(userComment);

            // If not anonymous then record in the timeline of the user doing the action
            if (userId != null)
            {
                repository.Save(new TimeLine(userId, TimeLineEntry.LikeComment, userComment.MemeId, userCommentId, null, null));
            }
            return(userComment);
        }
Esempio n. 6
0
 /// <summary>
 /// Add a user comment
 /// </summary>
 /// <param name="userComment"></param>
 /// <returns></returns>
 public IUserComment Save(IUserComment userComment)
 {
     userComment.Id = userComment.Id ?? NewLongId();
     userCommentCollection.Save(userComment.ToBsonDocument());
     return(userComment);
 }
Esempio n. 7
0
 /// <summary>
 /// Add a user comment
 /// </summary>
 /// <param name="userComment"></param>
 /// <returns></returns>
 public IUserComment Save(IUserComment userComment)
 {
     userComment.Id = userComment.Id ?? Guid.NewGuid().ToString("N");
       userCommentCollection.Save(userComment.ToBsonDocument());
       return userComment;
 }