Esempio n. 1
0
        public async Task <IActionResult> Comment(CommentViewModel commentViewModel)
        {
            if (ModelState.IsValid)
            {
                var post = _repository.Get(commentViewModel.PostID);

                if (commentViewModel.MainCommentId == 0)
                {
                    post.MainComments ??= new List <MainComment>();
                    post.MainComments.Add(new MainComment
                    {
                        Message = commentViewModel.Message,
                        Created = DateTime.Now
                    });
                    _repository.Update(post);
                }

                else
                {
                    var subComment = new SubComment
                    {
                        MainCommentId = commentViewModel.MainCommentId,
                        Message       = commentViewModel.Message,
                        Created       = DateTime.Now
                    };
                    _repository.AddSubComment(subComment);
                }
                await _repository.Save();

                return(RedirectToAction("Post", new { id = commentViewModel.PostID }));
            }
            return(RedirectToAction("Post", new { id = commentViewModel.PostID }));
        }
Esempio n. 2
0
        public async Task <IActionResult> SubCommentUpdate(SubComment vm)
        {
            var post = _uniofWork.Post.GetPostByMainCommentId(vm.MainCommentId);

            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Details", new { id = post.Id }));
            }

            if (ModelState.IsValid)
            {
                var comment = await _uniofWork.SubComment.GetByIdAsync(vm.Id);

                if (comment == null)
                {
                    return(RedirectToAction("Details", new { id = post.Id }));
                }

                // access to edit have admin, moderator and post author
                bool result = AccessRights.AuthorAdminAccessRight(HttpContext, comment.ApplicationUserId, _db);
                if (!result)
                {
                    return(new RedirectResult("~/Identity/Account/AccessDenied"));
                }

                comment.Message = vm.Message;
                await _uniofWork.SaveChangesAsync();
            }

            return(RedirectToAction("Details", new { id = post.Id }));
        }
        public async Task <IActionResult> Comment(CommentViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("ViewBlog", new { id = vm.BlogId }));
            }

            var blog = _repo.GetBlog(vm.BlogId);

            if (vm.MainCommentId == 0)
            {
                blog.MainComments = blog.MainComments ?? new List <MainComment>();

                blog.MainComments.Add(new MainComment
                {
                    Message = vm.Message,
                    Created = DateTime.Now,
                });
                _repo.UpdateBlog(blog);
            }
            else
            {
                var comment = new SubComment
                {
                    MainCommentId = vm.MainCommentId,
                    Message       = vm.Message,
                    Created       = DateTime.Now,
                };
                _repo.AddSubComment(comment);
            }

            await _repo.SaveChangesAsync();

            return(RedirectToAction("ViewBlog", new { id = vm.BlogId }));
        }
Esempio n. 4
0
        public async Task <IActionResult> Comment(CommentViewModel cvm)
        {
            if (!ModelState.IsValid)
            {
                //return RedirectToAction("Details", new { id = cvm.PostId });
                return(View(cvm.PostId));
            }

            var post = _postRepository.GetPostId(cvm.PostId);

            if (cvm.MainCommentId == 0)
            {
                post.MainComments = post.MainComments ?? new List <MainComment>();
                post.MainComments.Add(new MainComment
                {
                    PostId     = cvm.PostId,
                    Message    = cvm.Message,
                    CreateTime = DateTime.Now
                });
                _postRepository.UpdatePost(post);
            }
            else
            {
                var comment = new SubComment
                {
                    MainCommentId = cvm.MainCommentId,
                    Message       = cvm.Message,
                    CreateTime    = DateTime.Now
                };
                _postRepository.AddComment(comment);
            }
            await _postRepository.SaveChangesAsync();

            return(RedirectToAction("Details", new { id = cvm.PostId }));
        }
        public ActionResult AddSubComment(SubCommentsVM subComment, int ComID)
        {
            SubComment subCommentEntity = null;
            // int userId = (int)Session["UserID"];
            string      currentUserId = User.Identity.GetUserId();
            int         userId        = 1;
            List <User> GetUsers      = sp.GetUsers();

            var user    = GetUsers.FirstOrDefault(u => u.Id == currentUserId);
            var comment = sp.GetComments().FirstOrDefault(p => p.ComID == ComID);

            if (subComment != null)
            {
                subCommentEntity = new SubComment
                {
                    CommentMsg    = subComment.CommentMsg,
                    CommentedDate = DateTime.Now
                                    //subComment.CommentedDate,
                };


                if (user != null && comment != null)
                {
                    comment.SubComments.Add(subCommentEntity);
                    user.SubComments.Add(subCommentEntity);
                    sc.Commit();
                    su.Commit();
                    sp.Commit();
                    //  dbContext.SaveChanges();
                    //result = true;
                }
            }

            return(RedirectToAction("GetSubComments", "Comments", new { ComID = ComID }));
        }
Esempio n. 6
0
        public ActionResult AddSubComment(string subComment, int ComID)
        {
            // add sub comment
            string userId = User.Identity.GetUserId();

            string commentMsg = Request.Form["commentMsg"];

            Console.WriteLine(commentMsg + "id is" + userId + ComID);

            if (commentMsg != null)
            {
                var commentEntity = new SubComment
                {
                    CommentMessage = commentMsg,
                    CommentedDate  = DateTime.Now,
                    UserId         = userId,
                    CommentId      = ComID
                };

                //Console.WriteLine(commentEntity);

                db.SubComments.Add(commentEntity);
                //db.SaveChangesAsync();
                db.SaveChanges();
            }

            return(RedirectToAction("GetSubComments", "Discussion", new { ComID = ComID }));
        }
        public async Task <IActionResult> Comment(CommentViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(Post(vm.PostId));
            }

            var post = _repo.GetPost(vm.PostId);

            if (vm.MainCommentId > 0)
            {
                post.MainComments = post.MainComments ?? new List <MainComment>();

                post.MainComments.Add(new MainComment
                {
                    Message = vm.Message,
                    Created = DateTime.Now,
                });
                _repo.UpdatePost(post);
            }
            else
            {
                var comment = new SubComment
                {
                    MainCommentId = vm.MainCommentId,
                    Message       = vm.Message,
                    Created       = DateTime.Now,
                };
            }
            await _repo.SaveChangesAsync();

            return(View());
        }
Esempio n. 8
0
        public void AltYorumSil(int id)
        {
            SubComment temp = _appDbContext.SubComments.FirstOrDefault(i => i.Id == id);

            _appDbContext.SubComments.Remove(temp);
            _appDbContext.SaveChanges();
        }
Esempio n. 9
0
        public ActionResult AddSubComment(SubCommentsVM subComment, int ComID)
        {
            SubComment subCommentEntity = null;
            int        userId           = (int)Session["UserID"];

            var user    = dbContext.Users.FirstOrDefault(u => u.UserID == userId);
            var comment = dbContext.Comments.FirstOrDefault(p => p.ComID == ComID);

            if (subComment != null)
            {
                subCommentEntity = new EDMX.SubComment
                {
                    CommentMsg    = subComment.CommentMsg,
                    CommentedDate = subComment.CommentedDate,
                };


                if (user != null && comment != null)
                {
                    comment.SubComments.Add(subCommentEntity);
                    user.SubComments.Add(subCommentEntity);

                    dbContext.SaveChanges();
                    //result = true;
                }
            }

            return(RedirectToAction("GetSubComments", "Comments", new { ComID = ComID }));
        }
Esempio n. 10
0
        public async Task <IActionResult> Comment(CommentViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = vm.PostId }));
            }
            var post = await _repo.GetPost(vm.PostId);

            if (vm.MainCommentId == 0)
            {
                post.MainComments = post.MainComments ?? new List <MainComment>();
                post.MainComments.Add(new MainComment
                {
                    Name    = vm.Name,
                    Message = vm.Message,
                    Created = DateTime.Now,
                });
                _repo.UpdatePost(post);
            }
            else
            {
                var subComment = new SubComment
                {
                    MainCommentId = vm.MainCommentId,
                    Name          = vm.Name,
                    Message       = vm.Message,
                    Created       = DateTime.Now
                };
                _repo.AddSubComment(subComment);
            }
            await _repo.SaveChangesAsync();

            return(RedirectToAction("Post", new { id = vm.PostId }));
        }
Esempio n. 11
0
        public async Task AddComment(CommentViewModel vm)
        {
            var image = await this.GetImageAsync <Image>(vm.ImageId);

            if (vm.MainCommentId == 0)
            {
                image.MainComments.Add(new MainComment()
                {
                    Message  = vm.Message,
                    Created  = DateTime.Now,
                    UserName = this.userService.GetCurrentUserNames(),
                });
            }
            else
            {
                var mainComment = image.MainComments.FirstOrDefault(c => c.Id == vm.MainCommentId);
                var comment     = new SubComment()
                {
                    MainCommentId = vm.MainCommentId,
                    Message       = vm.Message,
                    Created       = DateTime.Now,
                    UserName      = this.userService.GetCurrentUserNames(),
                };
                mainComment.SubComments.Add(comment);
            }

            await this.images.SaveChangesAsync();
        }
Esempio n. 12
0
        public async Task <IActionResult> Comment(CommentViewModel commentViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { Id = commentViewModel.PostId }));
            }

            var post = _repo.GetRiddle(commentViewModel.PostId);

            if (commentViewModel.MainCommentId == 0)
            {
                post.MainComments = post.MainComments ?? new List <MainComment>();

                post.MainComments.Add(new MainComment
                {
                    Message = commentViewModel.Message,
                    Created = DateTime.Now
                });
                _repo.Update(post);
            }
            else
            {
                var comment = new SubComment
                {
                    MainCommentId = commentViewModel.MainCommentId,
                    Message       = commentViewModel.Message,
                    Created       = DateTime.Now
                };
                _repo.AddSubComment(comment);
            }
            await _repo.SaveChangesAsync();

            return(RedirectToAction("Post", new { Id = commentViewModel.PostId }));
        }
Esempio n. 13
0
        public ActionResult EditSubComment(SubCommentDto subcommentDto)
        {
            SubComment subcomment = db.SubComments.FirstOrDefault(s => s.Id == subcommentDto.SubCommentId);

            subcomment.Text = subcommentDto.Text;
            db.SaveChanges();
            return(Json(1, JsonRequestBehavior.AllowGet));
        }
Esempio n. 14
0
        /// <summary>
        /// Add subcomment under main comment
        /// </summary>
        /// <param name="comment">subcomment object</param>
        public void AddSubComment(SubComment comment)
        {
            // add new subcomment into SubComments Dbset
            _applicationDbContext.SubComments.Add(comment);

            // save all changes done with DB context
            _applicationDbContext.SaveChanges();
        }
        public async Task <BaseResponse <CommentViewModel> > Handle(CreateSubCommentCommand command, CancellationToken cancellationToken)
        {
            if (IsNullOrEmpty(command.Message))
            {
                return(BaseResponse.Fail <CommentViewModel>(await _translator.GetTranslation("Comment", "NeedMessage")));
            }

            var comment = await _ctx.Comments
                          .Include(x => x.Match)
                          .ThenInclude(x => x.MatchUsers)
                          .FirstAsync(x => x.Id == command.CommentId, cancellationToken: cancellationToken);

            if (comment == null)
            {
                return(BaseResponse.Fail <CommentViewModel>(await _translator.GetTranslation("Comment", "NotFound")));
            }

            var user = await _ctx.UserInformation
                       .FirstAsync(x => x.Id == command.UserId, cancellationToken : cancellationToken);

            if (user == null)
            {
                return(BaseResponse.Fail <CommentViewModel>(await _translator.GetTranslation("User", "NotFound")));
            }

            var subComment = new SubComment
            {
                Picture     = user.Picture,
                DisplayName = user.DisplayName,
                Message     = command.Message,
                TaggedUser  = command.TaggedUser
            };

            comment.SubComments.Add(subComment);
            await _ctx.SaveChangesAsync(cancellationToken);

            if (!IsNullOrEmpty(command.TaggedUser))
            {
                var taggedUser =
                    await _ctx.UserInformation.FirstAsync(x => x.DisplayName == command.TaggedUser, cancellationToken);

                _notification.QueueNotification(
                    await _translator.GetTranslation("Notification", "CommentReply", user.DisplayName),
                    new[] { comment.MatchId.ToString(), comment.Id.ToString(), subComment.Id.ToString() }.DefaultJoin(),
                    NotificationMessageType.SubComment,
                    new[] { taggedUser.Id });
            }

            _notification.QueueNotification(
                await _translator.GetTranslation("Notification", "CommentCreated", user.DisplayName),
                new[] { comment.MatchId.ToString(), comment.Id.ToString(), subComment.Id.ToString() }.DefaultJoin(),
                NotificationMessageType.SubComment,
                comment.Match.GetOtherUserIds(user.Id));


            return(BaseResponse.Ok(await _translator.GetTranslation("Comment", "Created"),
                                   CommentViewModel.CommentProjection.Compile().Invoke(comment)));
        }
Esempio n. 16
0
        public async Task <CommentViewModel> Handle(CreateSubCommentCommand command, CancellationToken cancellationToken)
        {
            if (IsNullOrEmpty(command.Message))
            {
                throw new Exception("Comment needs a message.");
            }

            var comment = await _ctx.Comments
                          .Include(x => x.Match)
                          .ThenInclude(x => x.MatchUsers)
                          .FirstAsync(x => x.Id == command.CommentId, cancellationToken: cancellationToken);

            if (comment == null)
            {
                throw new Exception("Main comment not found.");
            }

            var user = await _ctx.UserInformation
                       .FirstAsync(x => x.Id == command.UserId, cancellationToken : cancellationToken);

            if (user == null)
            {
                throw new UserNotFoundException();
            }

            var subComment = new SubComment
            {
                Picture     = user.Picture,
                DisplayName = user.DisplayName,
                Message     = command.Message,
                TaggedUser  = command.TaggedUser
            };

            comment.SubComments.Add(subComment);

            await _ctx.SaveChangesAsync(cancellationToken);

            if (!IsNullOrEmpty(command.TaggedUser))
            {
                var taggedUser = await _ctx.UserInformation
                                 .FirstAsync(x => x.DisplayName == command.TaggedUser, cancellationToken : cancellationToken);

                _notification.QueueNotification(
                    $"{user.DisplayName} replied to your comment.",
                    new[] { comment.MatchId.ToString(), comment.Id.ToString(), subComment.Id.ToString() }.DefaultJoin(),
                    NotificationMessageType.SubComment,
                    new[] { taggedUser.Id });
            }

            _notification.QueueNotification(
                $"{user.DisplayName} commented on your battle.",
                new[] { comment.MatchId.ToString(), comment.Id.ToString(), subComment.Id.ToString() }.DefaultJoin(),
                NotificationMessageType.SubComment,
                comment.Match.GetOtherUserIds(user.Id));

            return(CommentViewModel.SubCommentProjection.Compile().Invoke(subComment));
        }
Esempio n. 17
0
        public ActionResult DeleteSubComment(int?subcommentId)
        {
            SubComment  subcomment = db.SubComments.FirstOrDefault(s => s.Id == subcommentId);
            List <Like> list       = db.Likes.Where(s => subcommentId == s.SubCommentId).ToList();

            db.Likes.RemoveRange(list);
            db.SubComments.Remove(subcomment);
            db.SaveChanges();
            return(Json(1, JsonRequestBehavior.AllowGet));
        }
        public virtual async Task <SubComment> UpdateSubCommentAsync(SubComment subComment)
        {
            Preconditions.NotNull(subComment, nameof(subComment));

            _context.SubComments.Update(subComment);

            await SaveChangesAsync();

            return(subComment);
        }
Esempio n. 19
0
        public ActionResult SaveSubComment(SubCommentDto subCommentDto)
        {
            var        userName   = Session["userName"] as string;
            User       user       = db.Users.FirstOrDefault(us => us.UserName.Equals(userName));
            Comment    comment    = db.Comments.FirstOrDefault(s => s.Id == subCommentDto.CommentId);
            SubComment subComment = new SubComment
            {
                Text      = subCommentDto.Text,
                CommentId = subCommentDto.CommentId,
                UserId    = user.Id
            };

            db.SubComments.Add(subComment);
            db.SaveChanges();
            int           SubCommentId = db.SubComments.Max(s => s.Id);
            SubCommentDto result       = new SubCommentDto
            {
                UserNameComment = userName,
                UrlPersonal     = "/Home/Personal?id=" + user.Id.ToString(),
                UserName        = comment.User.UserName,
                LikeNumber      = 0,
                NameOfUser      = user.Name,
                Text            = subCommentDto.Text,
                Avatar          = user.Avatar,
                SubCommentId    = SubCommentId
            };

            if (user.Id != comment.User.Id)
            {
                Notification noti = new Notification
                {
                    UserId            = comment.User.Id,
                    PostId            = comment.Post.Id,
                    NameOfUser        = user.Name,
                    Avatar            = user.Avatar,
                    TextNoti          = "Đã trả lời bình luận của bạn",
                    ClassIconName     = "far fa-comments",
                    NotificationState = false
                };
                db.Notifications.Add(noti);
            }
            NotifiDto notiDto = new NotifiDto
            {
                NameOfUser  = user.Name,
                SubjectName = comment.Post.Subject.Name,
                Avatar      = user.Avatar,
                SubjectId   = comment.Post.SubjectId,
                TimeNotifi  = comment.Post.CreatedDate,
                PostId      = comment.Post.Id,
                TextNoti    = "Đã trả lời bình luận của bạn"
            };

            db.SaveChanges();
            return(Json(new { result, notiDto }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 20
0
 public IHttpActionResult PostAReplayAComment(SubComment subComment)
 {
     if (!ModelState.IsValid)
     {
         return(BadRequest());
     }
     subComment.TimeStamp = DateTime.Now;
     db.SubComments.Add(subComment);
     db.SaveChanges();
     return(Created(new Uri(Request.RequestUri + "/" + subComment.Id), subComment));
 }
Esempio n. 21
0
        public ActionResult SubCommentsDeleteConfirmed(int id)
        {
            if (!isAdminUser())
            {
                return(RedirectToAction("Index", "User"));
            }
            SubComment subComment = db.SubComments.Find(id);

            db.SubComments.Remove(subComment);
            db.SaveChanges();
            return(RedirectToAction("SubCommentsIndex"));
        }
        public async Task AddCommentFromCommentView(CommentVM vm, Claim claim)
        {
            var comment = new SubComment
            {
                MainCommentId     = vm.MainCommentId,
                Message           = vm.Message,
                Created           = DateTime.Now,
                ApplicationUserId = claim.Value,
            };

            _context.SubComments.Add(comment);
            await _context.SaveChangesAsync();
        }
Esempio n. 23
0
        public IActionResult Comment(CommentViewModel commentVM)
        {
            // find game by gameID
            var game = _gameRepository.GetGameById(commentVM.GameID);

            // if model is not valid
            if (!ModelState.IsValid)
            {
                // redirect to same page
                return(RedirectToAction(game.Name, "Game/Single"));
            }

            // if it is no main comment
            if (commentVM.MainCommentID == 0)
            {
                // create comments collection
                game.MainComments = game.MainComments ?? new List <MainComment>();

                // add new main comment into collection
                game.MainComments.Add(new MainComment
                {
                    Message  = commentVM.Message,
                    UserName = commentVM.UserName,
                    Created  = DateTime.Now
                });

                // add main comment into context
                _gameRepository.AddMainComment(game);

                //var comments = _gameRepository.Games.FirstOrDefault(g => g.Name == game.Name).MainComments;
            }

            // if maincommentID !=0 -> so we leave sub comment under main comment
            else
            {
                // create new sub comment
                var comment = new SubComment
                {
                    MainCommentID = commentVM.MainCommentID,
                    Message       = commentVM.Message,
                    UserName      = commentVM.UserName,
                    Created       = DateTime.Now
                };

                // add sub comment into context
                _gameRepository.AddSubComment(comment);
            }

            // redirect to the same page
            return(RedirectToAction("Single", new { gameName = game.Name }));
        }
        public ActionResult AddSubComment(string subComment, int ComID)
        {
            // add sub comment
            string userId = User.Identity.GetUserId();

            string commentMsg = Request.Form["commentMsg"];

            Console.WriteLine(commentMsg + "id is" + userId + ComID);

            if (commentMsg != null)
            {
                var commentEntity = new SubComment
                {
                    CommentMessage = commentMsg,
                    CommentedDate  = DateTime.Now,
                    UserId         = userId,
                    CommentId      = ComID
                };

                //Console.WriteLine(commentEntity);

                db.SubComments.Add(commentEntity);
                //db.SaveChangesAsync();
                db.SaveChanges();

                var comment    = db.DiscussionComments.Where(x => x.Id == ComID).FirstOrDefault();
                var discussion = db.Discussions.Where(x => x.Id == comment.DiscussionId).FirstOrDefault();

                var preference = GetUserNotificationPreference("discussion", discussion.UserId);
                var subcom     = db.DiscussionComments.Where(x => x.Id == ComID).FirstOrDefault();

                var userModel = GetUserInfoByUserId(subcom.Discussion.UserId);

                var    loginUser = GetUserInfoByUserId(userId);
                string body      = "A new comment has been posted on discussion: " + subcom.Discussion.Topic + " by " + loginUser.FullName;
                if (preference.IsEmail)
                {
                    var recipients = new List <EmailAddress>();
                    recipients.Add(new EmailAddress(userModel.Email, userModel.FullName));
                    SendEmailViaSendGrid("Interest showed in meeting", body, recipients);
                }

                if (preference.IsSms)
                {
                    SendSmsViaClickaTell("+16475372344", body);
                }
            }

            return(RedirectToAction("GetSubComments", "Discussion", new { ComID = ComID }));
        }
Esempio n. 25
0
 public ActionResult SubCommentsEdit([Bind(Include = "SubCommentId,EvidenceCommentId,Name,Email,Date,Content")] SubComment subComment)
 {
     if (!isAdminUser())
     {
         return(RedirectToAction("Index", "User"));
     }
     if (ModelState.IsValid)
     {
         db.Entry(subComment).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("SubCommentsIndex"));
     }
     return(View("SubComments/Edit", subComment));
 }
        public virtual async Task <SubComment> InsertSubCommentAsync(SubComment subComment)
        {
            Preconditions.NotNull(subComment, nameof(subComment));

            await BlogMustExist(subComment.BlogID);
            await MainCommentMustExit(subComment.MainCommentID);
            await ApplicationUserMustExist(subComment.ApplicationUserID);

            await _context.SubComments.AddAsync(subComment);

            await SaveChangesAsync();

            return(subComment);
        }
Esempio n. 27
0
        public ActionResult SubCommentsCreate([Bind(Include = "SubCommentId,EvidenceCommentId,Name,Email,Date,Content")] SubComment subComment)
        {
            if (!isAdminUser())
            {
                return(RedirectToAction("Index", "User"));
            }
            if (ModelState.IsValid)
            {
                db.SubComments.Add(subComment);
                db.SaveChanges();
                return(RedirectToAction("SubCommentsIndex"));
            }

            return(View("SubComments/Create", subComment));
        }
Esempio n. 28
0
        //SubCommentService
        public bool AddSubComment(SubComment subComment)
        {
            var result = db.Comment.Where(x => x.Id == subComment.CommentId).FirstOrDefault();

            if (result == null)
            {
                return(false);
            }
            else
            {
                db.SubComment.InsertOnSubmit(subComment);
                db.SubmitChanges();
                return(true);
            }
        }
        public JsonResult SaveLikeSubComment(int?id)
        {
            var     userName = Session["userName"] as string;
            User    user     = db.Users.FirstOrDefault(us => us.UserName.Equals(userName));
            LikeDto result   = new LikeDto
            {
                Check    = false,
                UserName = ""
            };
            Like like = db.Likes.FirstOrDefault(s => s.UserId == user.Id && s.SubCommentId == id);

            if (like != null)
            {
                db.Likes.Remove(like);
            }
            else
            {
                Like like2 = new Like {
                    SubCommentId = id, UserId = user.Id
                };
                db.Likes.Add(like2);
                result.Check = true;
            }
            if (result.Check)
            {
                SubComment subcomment = db.SubComments.FirstOrDefault(s => s.Id == id);
                if (subcomment.UserId != user.Id)
                {
                    Notification noti = new Notification
                    {
                        UserId            = subcomment.UserId,
                        PostId            = subcomment.Comment.PostId,
                        NameOfUser        = user.Name,
                        Avatar            = user.Avatar,
                        TextNoti          = "Đã thích bình luận của bạn",
                        ClassIconName     = "far fa-thumbs-up",
                        NotificationState = false
                    };
                    result.UserName = subcomment.User.UserName;
                    db.Notifications.Add(noti);
                }
            }
            db.SaveChanges();

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public async Task <IActionResult> Comment(CommentViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(RedirectToAction("Post", new { id = vm.PostId }));
            }

            var post = _repo.GetPost(vm.PostId);

            if (vm.MainCommentId == 0)
            {
                var user = await _userManager.GetUserAsync(User);

                var email = user.Email;
                post.MainComments = post.MainComments ?? new List <MainComment>();

                post.MainComments.Add(new MainComment
                {
                    Message = vm.Message,
                    Created = DateTime.Now,
                    Edited  = DateTime.Now,
                    By      = user.FirstName,
                    UserId  = user.Id
                });
                _repo.UpdatePost(post);
            }
            else
            {
                var user = await _userManager.GetUserAsync(User);

                var email   = user.Email;
                var comment = new SubComment
                {
                    MainCommentId = vm.MainCommentId,
                    Message       = vm.Message,
                    Created       = DateTime.Now,
                    Edited        = DateTime.Now,
                    By            = user.FirstName,
                    UserId        = user.Id
                };
                _repo.AddSubComment(comment);
            }
            await _repo.SaveChangesAsync();

            return(RedirectToAction("Post", new { id = vm.PostId }));
        }