public HttpResponseMessage CreateComment([FromBody] CommentSerializer comment) { try { var res = Entities.CommentCreate(CurrentIdentity.UserId, comment.PostId, comment.Content).FirstOrDefault(); var resultComment = new Comment { UserId = res.UserId, CommentId = res.CommentId, Content = res.Content, CreatedAt = res.CreatedAt, FirstName = res.FirstName, LastName = res.LastName, PostId = res.PostId, UserPicture = res.UserPicture, Visible = res.Visible }; return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = true, Message = "Comment Created successfully.", Data = resultComment })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ResponseMessage { Success = false, Message = ex.Message })); } }
private Models.Post PackPost(GroupPostsGet_Result foundPost, List <PostCommentsGet_Result> foundComments) { var post = new Models.Post(); var comments = new List <Comment>(); foreach (var comment in foundComments) { var tempComment = new Comment(); comment.CopyProperties <PostComment, Comment>(tempComment); comments.Add(tempComment); } foundPost.CopyProperties <GroupPostsGet_Result, Models.Post>(post); //foundComments.CopyProperties<CommentGet_Result, List<Comment>>(comments); post.Comments = new List <Comment>(comments); post.Likes = Entities.Likes.Count(l => l.PostId == post.PostId); post.Liked = Entities.Likes.Count(l => l.PostId == post.PostId && l.UserId == CurrentIdentity.UserId) > 0; return(post); }
public HttpResponseMessage UpdatePost([FromBody] PostSerializer post) { try { var res = Entities.PostEdit(post.PostId, post.Content, null).FirstOrDefault(); var resultComment = new Comment { UserId = res.UserId, PostId = res.PostId, Content = res.Content, CreatedAt = res.CreatedAt, FirstName = res.FirstName, LastName = res.LastName, UserPicture = res.UserPicture, Visible = res.Visible, ModifiedAt = res.ModifiedAt, Likes = Entities.Likes.Count(l => l.CommentId == post.PostId), Liked = Entities.Likes.FirstOrDefault( l => l.UserId == CurrentIdentity.UserId.Value && l.CommentId == post.PostId) != null }; return(Request.CreateResponse(HttpStatusCode.OK, new ResponseMessage { Success = true, Message = "Post updated successfully.", Data = resultComment })); } catch (Exception ex) { return(Request.CreateResponse(HttpStatusCode.InternalServerError, new ResponseMessage { Success = false, Message = ex.Message })); } }