Exemplo n.º 1
0
        public async Task <IActionResult> Edit(EditCommentInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest());
            }

            if (!await this.commentsService.CommentExists(input.Id))
            {
                return(this.NotFound());
            }

            var user = await this.userManager.GetUserAsync(this.User);

            var isAdmin = await this.userManager.IsInRoleAsync(user, GlobalConstants.AdministratorRoleName);

            if (!await this.commentsService.IsUserCommentAuthor(input.Id, user.Id) && !isAdmin)
            {
                return(this.BadRequest());
            }

            await this.commentsService.EditAsync(input.Content, input.Id);

            return(this.RedirectToAction("ById", "Posts", new { Id = input.PostId }));
        }
Exemplo n.º 2
0
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }

            var comment = this.Data.Comments.Find(id);

            if (comment == null)
            {
                return this.HttpNotFound();
            }

            if (comment.UserId != this.UserProfile.Id)
            {
                return this.HttpNotFound();
            }

            var model = new EditCommentInputModel
            {
                Id = comment.Id,
                Content = comment.Content,
                CreatedOn = comment.CreatedOn,
                BlogPostId = comment.PostId,
                UserId = comment.UserId
            };

            return this.View(model);
        }
        public async Task UpdateAsync(EditCommentInputModel inputModel)
        {
            Comment comment = this.commentRepository
                              .All()
                              .FirstOrDefault(c => c.Id == inputModel.CommentId);

            comment.Content = inputModel.Content;

            await this.commentRepository.SaveChangesAsync();
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Edit(EditCommentInputModel input)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.Redirect($"/Topics/Details?topicId={input.TopicId}"));
            }

            await this.commentsService.EditAsync(input.Id, input.CommentContent);

            return(this.Redirect($"/Topics/Details?topicId={input.TopicId}"));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> Edit(EditCommentInputModel input)
        {
            if (input.AuthorUserName != this.User.Identity.Name)
            {
                return(this.BadRequest());
            }

            await this.commentsService.Edit(input.Id, input.Content);

            return(this.RedirectToAction("ById", "Posts", new { id = input.PostId }));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> EditComment(string commentId, string postId)
        {
            var isCommentIdCorrect = await this.commentsService.IsCommentIdCorrect(commentId, postId);

            if (!isCommentIdCorrect)
            {
                this.TempData["Error"] = ErrorMessages.InvalidInputModel;
                return(this.RedirectToAction("Index", "Post", new { postId }));
            }

            EditCommentInputModel model = await this.commentsService.GetCommentById(commentId);

            return(this.View(model));
        }
        public async Task <IActionResult> Edit(EditCommentInputModel inputModel, int id)
        {
            if (!this.ModelState.IsValid)
            {
                inputModel = this.commentsService.GetById <EditCommentInputModel>(id);
                return(this.View(inputModel));
            }

            int?postId = this.commentsService.GetPostId(id);

            inputModel.CommentId = id;
            await this.commentsService.UpdateAsync(inputModel);

            return(this.RedirectToAction("SeePost", "Posts", new { Id = postId }));
        }
Exemplo n.º 8
0
        public async Task <Tuple <string, string> > EditComment(EditCommentInputModel model)
        {
            var comment = await this.db.Comments.FirstOrDefaultAsync(x => x.Id == model.Id);

            if (comment != null)
            {
                comment.Content   = model.SanitizedContent;
                comment.UpdatedOn = DateTime.UtcNow;
                this.db.Update(comment);
                await this.db.SaveChangesAsync();

                return(Tuple.Create("Success", SuccessMessages.SuccessfullyEditedComment));
            }

            return(Tuple.Create("Error", ErrorMessages.InvalidInputModel));
        }
Exemplo n.º 9
0
        public ActionResult Edit(EditCommentInputModel commentInputModel)
        {
            if (this.ModelState.IsValid)
            {
                var comment = this.Data.Comments.Find(commentInputModel.Id);

                comment.Id = commentInputModel.Id;
                comment.Content = commentInputModel.Content;
                comment.CreatedOn = commentInputModel.CreatedOn;
                comment.PostId = commentInputModel.BlogPostId;
                comment.UserId = commentInputModel.UserId;

                this.Data.Comments.Update(comment);
                this.Data.SaveChanges();

                return this.RedirectToAction("Index", "Post", new
                {
                    id = commentInputModel.BlogPostId
                });
            }

            return this.View(commentInputModel);
        }
        public IActionResult Edit(int id)
        {
            EditCommentInputModel inputModel = this.commentsService.GetById <EditCommentInputModel>(id);

            return(this.View(inputModel));
        }
Exemplo n.º 11
0
        public async Task <IActionResult> EditComment(string commentId, string postId, EditCommentInputModel model)
        {
            if (this.ModelState.IsValid)
            {
                var isCommentIdCorrect = await this.commentsService.IsCommentIdCorrect(commentId, postId);

                if (!isCommentIdCorrect)
                {
                    this.TempData["Error"] = ErrorMessages.InvalidInputModel;
                    return(this.RedirectToAction("Index", "Post", new { postId }));
                }

                Tuple <string, string> tuple = await this.commentsService.EditComment(model);

                this.TempData[tuple.Item1] = tuple.Item2;

                return(this.RedirectToAction("Index", "Post", new { postId }));
            }

            this.TempData["Error"] = ErrorMessages.InvalidInputModel;
            return(this.RedirectToAction("Index", "Blog"));
        }