Ejemplo n.º 1
0
        public IHttpActionResult Get(int postId)
        {
            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                List <CommentViewModel> comments = new List <CommentViewModel>();
                foreach (var x in db.Posts.Find(postId).Comments)
                {
                    CommentViewModel cvm = ApplicationUtils.CreateCommentViewModel(x);
                    cvm.Likes    = db.Database.SqlQuery <int>("SELECT COUNT(*) FROM Users_Comments_Like WHERE Comment_id = {0}", cvm.Id).First();
                    cvm.Dislikes = db.Database.SqlQuery <int>("SELECT COUNT(*) FROM Users_Comments_Dislike WHERE Comment_id = {0}", cvm.Id).First();

                    comments.Add(cvm);
                }
                return(Ok(new { Comments = comments }));
            }
        }