//[CheckPermissionsToEditForComments]
        public async Task <ActionResult> Edit(Comment comment)
        {
            try
            {
                var originalComment = await _commentsService.FindAsync(comment.Id);

                if (originalComment == null)
                {
                    return(RedirectToAction("Show/" + comment.PostId, "Posts"));
                }

                if (!originalComment.AuthorId.Equals(User.Identity.GetUserId()))
                {
                    return(RedirectToAction("Show/" + comment.PostId, "Posts"));
                }


                originalComment.CommentBody = comment.CommentBody;
                await _commentsService.UpdateAsync(originalComment);

                return(RedirectToAction("Show/" + comment.PostId, "Posts"));
            }
            catch (DataException /* dex */)
            {
                //Log the error (uncomment dex variable name and add a line here to write a log.
                //ModelState.AddModelError("", "Unable to save changes. Try again, and if the problem persists, see your system administrator.");
            }

            return(View(comment));
        }
Exemple #2
0
        public override async Task <FindReply> Find(FindRequest request, ServerCallContext context)
        {
            _logger.LogInformation("Find Invoked");
            Comment co = await commentsService.FindAsync(request.Id);

            return(new FindReply()
            {
                Id = co.Id, PhotoId = co.PhotoId, Subject = co.Subject, UserName = co.UserName, Body = co.Body, SubmittedOn = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(co.SubmittedOn.ToUniversalTime())
            });
        }
        public override async Task <FindReply> Find(FindRequest request, ServerCallContext context)
        {
            Comment c = await commentsService.FindAsync(request.Id);

            if (c is null)
            {
                throw new RpcException(new Status(StatusCode.NotFound, "Comment not found"));
            }
            return(new FindReply()
            {
                Id = c.Id, PhotoId = c.PhotoId, Subject = c.Subject, UserName = c.UserName, Body = c.Body, SubmittedOn = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(c.SubmittedOn.ToUniversalTime())
            });
        }