Beispiel #1
0
        public async Task <IActionResult> Post([FromRoute] uint id, CommentPostRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            IssuePost post = (await Db.IssuePosts.AddAsync(new IssuePost()
            {
                AuthorId = HttpContext.User.IsAnonymous() ? null : new uint?((uint)HttpContext.User.GetUserId()),
                IssueId = id,
                ContainedText = req.Text,
                DateOfCreation = DateTime.UtcNow
            })).Entity;

            await Db.IssueActivities.AddIssueActivity(HttpContext, id, new PostActivity()
            {
                ContainedText = req.Text,
                Post          = post
            });

            await Db.SaveChangesAsync();

            return(RedirectToAction("ViewTalk", "Issue", new { id = id }, post.Id.ToString()));
        }
        public async Task <IActionResult> Comment([FromRoute] string path, CommentPostRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(Forbid());
            }
            var page = await Db.Infopages.SingleAsync(x => x.Path == path.Replace("%2F", "/", true, CultureInfo.InvariantCulture));

            if (!HttpContext.UserCan("kb.secrecy." + page.Secrecy.ToString()))
            {
                return(Forbid());
            }
            InfopageComment post = (await Db.InfopageComments.AddAsync(new InfopageComment()
            {
                AuthorId = HttpContext.User.IsAnonymous() ? null : new uint?((uint)HttpContext.User.GetUserId()),
                Infopage = page,
                ContainedText = req.Text,
                DateOfCreation = DateTime.UtcNow
            })).Entity;

            await Db.KBActivities.AddKBActivity(HttpContext, page.Id, new CommentActivity()
            {
                Comment       = post,
                ContainedText = req.Text
            });

            await Db.SaveChangesAsync();

            return(RedirectToAction("ViewTalk", "KnowledgeBase", new { path = path.Replace("%2F", "/", true, CultureInfo.InvariantCulture) }, post.Id.ToString()));
        }
        public async Task <IActionResult> EditComment([FromRoute] uint id, CommentPostRequest req)
        {
            InfopageComment comment = await Db.InfopageComments
                                      .Include(x => x.Infopage)
                                      .SingleAsync(x => x.Id == id);

            if (!HttpContext.UserCan("kb.editcomment.all") &&
                !(HttpContext.UserCan("kb.editcomment.own") && ((int?)comment.AuthorId ?? -1) == HttpContext.User.GetUserId()))
            {
                if (HttpContext.User.IsAnonymous())
                {
                    return(Challenge());
                }
                else
                {
                    return(Forbid());
                }
            }
            if (!ModelState.IsValid)
            {
                return(View(comment));
            }

            if (!HttpContext.UserCan("kb.secrecy." + comment.Infopage.Secrecy.ToString()))
            {
                return(Forbid());
            }

            await Db.KBActivities.AddKBActivity(HttpContext, comment.Infopage.Id, new EditCommentActivity()
            {
                CommentId        = id,
                OldContainedText = comment.ContainedText,
                NewContainedText = req.Text
            });

            comment.DateOfEdit    = DateTime.UtcNow;
            comment.ContainedText = req.Text;

            await Db.SaveChangesAsync();

            return(RedirectToAction("ViewTalk", "KnowledgeBase", new { path = comment.Infopage.Path }, comment.Id.ToString()));
        }
Beispiel #4
0
        public async Task <IActionResult> EditPost([FromRoute] uint id, CommentPostRequest req)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            IssuePost post = await Db.IssuePosts.FindAsync(id);

            if (!HttpContext.UserCan("issue.editpost.all") &&
                !(HttpContext.UserCan("issue.editpost.own") && ((int?)post.AuthorId ?? -1) == HttpContext.User.GetUserId()))
            {
                if (HttpContext.User.IsAnonymous())
                {
                    return(Challenge());
                }
                else
                {
                    return(Forbid());
                }
            }

            if (post.ContainedText != req.Text)
            {
                await Db.IssueActivities.AddIssueActivity(HttpContext, id, new EditPostActivity()
                {
                    OldContainedText = post.ContainedText,
                    NewContainedText = req.Text,
                    PostId           = id
                });

                post.DateOfEdit    = DateTime.UtcNow;
                post.ContainedText = req.Text;

                await Db.SaveChangesAsync();
            }

            return(RedirectToAction("ViewTalk", "Issue", new { id = post.IssueId }, post.Id.ToString()));
        }