public ActionResult Create(CR_ComentarioReview cr_comentarioreview)
        {
            if (ModelState.IsValid)
            {
                bool wasNotApproved = Extensions.ExtensionHelper.NotApproved(cr_comentarioreview.CR_Comentario);
                if (wasNotApproved)
                {
                    cr_comentarioreview.ST_Id = 7;
                }
                else
                    cr_comentarioreview.ST_Id = 1;
                db.SaveChanges<CR_ComentarioReview>(cr_comentarioreview);
                var user = db.UserProfile.Find(WebSecurity.CurrentUserId);
                CommentReview cmt = new CommentReview { Comments = cr_comentarioreview.CR_Comentario, Image = Url.Content(string.IsNullOrEmpty(user.Image) ? "~/Images/No_Profile.jpg" : user.Image), Name = user.Name };
                if (Request.IsAjaxRequest())
                {
                    return Json(new { data = cmt }.SerializeToJson());
                }
                return RedirectToAction("Index");
            }

            ViewBag.RW_Id = new SelectList(db.RW_Reviews, "RW_Id", "RW_Comentario", cr_comentarioreview.RW_Id);
            ViewBag.ST_Id = new SelectList(db.ST_Estatus, "ST_Id", "ST_Descripcion", cr_comentarioreview.ST_Id);
            ViewBag.UserId = new SelectList(db.UserProfile, "UserId", "UserName", cr_comentarioreview.UserId);
            if (Request.IsAjaxRequest())
            {
                return Json(new { error = true }.SerializeToJson());
            }
            return View(cr_comentarioreview);
        }
        public async Task <bool> CreateCommentReview(Guid commentId)
        {
            var commentReview = new CommentReview
            {
                CommentId = commentId
            };

            return(await _commentReviewSvc.CreateAsync(commentReview));
        }
 public IHttpActionResult PostComment(Guid appId, CommentReview review)
 {
     try
     {
         using (MususAppEntities entity = new MususAppEntities())
         {
             if (review != null)
             {
                 if (review.Id > 0)
                 {
                     var post = entity.Posts.FirstOrDefault(x => x.Id == review.Id);
                     post.Txt        = review.Comment;
                     post.CreateTime = DateTime.UtcNow;
                     if (post != null && review.Review != null)
                     {
                         entity.SaveChanges();
                         var comment = entity.Comments.FirstOrDefault(x => x.PostId == post.Id);
                         comment.Msg        = review.Review;
                         comment.UserName   = review.ReviewUsername;
                         comment.CreateTime = DateTime.UtcNow;
                     }
                 }
                 else
                 {
                     var post = entity.Posts.Add(new Post()
                     {
                         AppId      = appId,
                         CreateTime = DateTime.UtcNow,
                         Txt        = review.Comment,
                         UserName   = review.Username
                     });
                     entity.SaveChanges();
                     if (post != null)
                     {
                         entity.Comments.Add(new Comment()
                         {
                             CreateTime = DateTime.UtcNow,
                             PostId     = post.Id,
                             Msg        = review.Review,
                             UserName   = null
                         });
                     }
                 }
             }
             entity.SaveChanges();
             return(Ok());
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
        private static void GetPostComment(MususAppEntities entity, AppMaster appMaster, AppMasterDto app, string userName)
        {
            var userPost = entity.Posts.FirstOrDefault(x => x.AppId == appMaster.Id && x.UserName == userName);

            if (userPost != null)
            {
                var userCR = new CommentReview()
                {
                    Comment     = userPost.Txt,
                    CommentDate = userPost.CreateTime,
                    Username    = userName,
                    Id          = userPost.Id
                };
                var userComment = entity.Comments.FirstOrDefault(x => x.PostId == userPost.Id);
                if (userComment != null)
                {
                    userCR.Review         = userComment.Msg;
                    userCR.ReviewDate     = userComment.CreateTime;
                    userCR.ReviewUsername = userComment.UserName;
                }
                app.UserComment = userCR;
            }
            if (app.UserComment == null)
            {
                var posts = entity.Posts.Where(x => x.AppId == appMaster.Id).OrderByDescending(x => x.CreateTime);
                if (posts != null)
                {
                    foreach (var post in posts)
                    {
                        var review = entity.Comments.FirstOrDefault(x => x.PostId == post.Id);
                        if (review != null)
                        {
                            app.CommentReviews.Add(new CommentReview()
                            {
                                Id             = post.Id,
                                Comment        = post.Txt,
                                CommentDate    = post.CreateTime,
                                Review         = review.Msg,
                                ReviewDate     = review.CreateTime,
                                ReviewUsername = review.UserName,
                                Username       = post.UserName
                            });
                        }
                        else
                        {
                            app.CommentReviews.Add(new CommentReview()
                            {
                                Id          = post.Id,
                                Comment     = post.Txt,
                                CommentDate = post.CreateTime
                            });
                        }
                    }
                }
            }
            else
            {
                var posts = entity.Posts.Where(x => x.AppId == appMaster.Id).OrderByDescending(x => x.CreateTime);
                if (posts != null)
                {
                    foreach (var post in posts)
                    {
                        var review = entity.Comments.FirstOrDefault(x => x.PostId == post.Id);
                        if (review != null)
                        {
                            app.CommentReviews.Add(new CommentReview()
                            {
                                Id             = post.Id,
                                Comment        = post.Txt,
                                CommentDate    = post.CreateTime,
                                Review         = review.Msg,
                                ReviewDate     = review.CreateTime,
                                ReviewUsername = review.UserName,
                                Username       = post.UserName
                            });
                        }
                        else
                        {
                            app.CommentReviews.Add(new CommentReview()
                            {
                                Id          = post.Id,
                                Comment     = post.Txt,
                                CommentDate = post.CreateTime
                            });
                        }
                    }
                }
            }
        }