public async Task <IActionResult> Comment(GroupPostCommentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var user = await CurrentUser();

                var post = await _groupRepository.GetPostByIdAsync(vm.PostId);

                if (post == null)
                {
                    return(NotFound());
                }
                var comment = new GroupPostComment
                {
                    Name         = vm.Name,
                    Body         = vm.Body,
                    Post         = post,
                    Owner        = user,
                    CreationDate = DateTime.UtcNow
                };

                await _groupRepository.AddCommentAsync(comment);

                return(RedirectToAction(nameof(SwitchToTabs), new { tabname = "GroupPosts", id = vm.GroupId }));
            }
            return(View(vm));
        }
        public async Task <IActionResult> EditComment(long?id, long groupId)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var comment = await _groupRepository.GetPostCommentByIdAsync(id.Value);

            if (comment == null)
            {
                return(NotFound());
            }

            if (comment.Owner.Email != User.Identity.Name)
            {
                return(Unauthorized());
            }

            var postComment = new GroupPostCommentViewModel
            {
                GroupId      = groupId,
                Id           = comment.Id,
                PostId       = comment.Post.Id,
                Body         = comment.Body,
                Name         = comment.Name,
                CreationDate = comment.CreationDate,
                Owner        = comment.Owner,
                Post         = comment.Post,
                OwnerId      = comment.Owner.Id
            };

            return(View(postComment));
        }
        public async Task <IActionResult> Comment(long id, long groupId)
        {
            if (!await CanPostOrComment(groupId))
            {
                return(Unauthorized());
            }

            var postComment = new GroupPostCommentViewModel
            {
                PostId  = id,
                GroupId = groupId
            };

            return(View(postComment));
        }
        public async Task <IActionResult> EditComment(long id, GroupPostCommentViewModel vm)
        {
            if (id != vm.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var user = await CurrentUser();

                if (user == null || user.Id != vm.OwnerId)
                {
                    return(NotFound());
                }
                //var post = await _groupRepository.GetPostByIdAsync(vm.PostId);
                //if (post == null)
                //{
                //    return NotFound();
                //}

                var comment = await _groupRepository.GetPostCommentByIdAsync(vm.Id);

                comment.Name        = vm.Name;
                comment.Body        = vm.Body;
                comment.UpdatedDate = DateTime.UtcNow;

                try
                {
                    await _groupRepository.UpdateCommentAsync(comment);
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!await PostCommentExists(comment.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(SwitchToTabs), new { tabname = "GroupPosts", id = vm.GroupId }));
            }
            return(View(vm));
        }