Exemplo n.º 1
0
        public static JToken ToJson(BaseComment c)
        {
            var obj = (JObject)ToJson((Entry)c);

            obj["content"] = c.Content;
            return(obj);
        }
Exemplo n.º 2
0
        public IHttpActionResult PostComment(BaseComment commentData)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            ApplicationUser currentUser = db.Users.Find(User.Identity.GetUserId());
            Post            currentPost = db.Posts.Find(commentData.PostId);

            Comment newComment = new Comment {
                Post       = currentPost,
                Content    = commentData.Content,
                Author     = (currentUser == null) ? "Anonymus" : currentUser.UserName,
                Engagement = new Engagement {
                    Likes = 0
                }
            };

            currentPost.Comments.Add(newComment);

            try
            {
                db.Comments.Add(newComment);
                db.SaveChanges();
            } catch (Exception E)
            {
                return(BadRequest("Not done"));
            }
            return(StatusCode(HttpStatusCode.OK));
        }
Exemplo n.º 3
0
        public static BaseComment Convert(this Comment model, IMapper _mapper)
        {
            BaseComment comment = _mapper.Map <Comment, BaseComment>(model);

            comment.Date = model.DatePosted.ToShortDateString();
            comment.Time = model.DatePosted.ToShortTimeString();
            return(comment);
        }
Exemplo n.º 4
0
        public IHttpActionResult Like(BaseComment currentComment)
        {
            Comment         comment     = db.Comments.Find(currentComment.CommentId);
            ApplicationUser currentUser = db.Users.Find(User.Identity.GetUserId());

            comment.LikedBy.Add(currentUser);
            comment.Engagement.Likes += 1;
            currentUser.LikedComments.Add(comment);

            db.SaveChanges();
            return(StatusCode(HttpStatusCode.OK));
        }