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));
        }
Beispiel #2
0
        public async Task <GroupPostComment> AddCommentAsync(GroupPostComment comment)
        {
            _context.Add(comment);
            await _context.SaveChangesAsync();

            return(comment);
        }
Beispiel #3
0
        public async Task <bool> DeleteCommentAsync(GroupPostComment comment)
        {
            _context.GroupPostComments.Remove(comment);
            int result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Beispiel #4
0
        public async Task <bool> UpdateCommentAsync(GroupPostComment comment)
        {
            _context.Update(comment);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
        }
Beispiel #5
0
        public static void WriteGroupPostComment(int userid, int postid, string content)
        {
            User      user = ctx.Users.First(u => u.Id == userid);
            GroupPost post = ctx.GroupPosts.First(p => p.Id == postid);

            GroupPostComment comment = new GroupPostComment();

            comment.Content     = content;
            comment.GroupPost   = post;
            comment.GroupPostId = postid;
            comment.User        = user;
            comment.UserId      = userid;

            ctx.GroupPostComments.Add(comment);
            ctx.SaveChanges();
        }
Beispiel #6
0
        public async Task <bool> DeleteCommentAsync(GroupPostComment comment)
        {
            comment.Deleted = true;
            _context.Update(comment);

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (Exception)
            {
                return(false);
            }

            return(true);
            //_context.GroupPostComments.Remove(comment);
            //int result = await _context.SaveChangesAsync();

            //return result > 0;
        }