public async Task <IActionResult> Edit(Guid?id, PostCommentEditModel model) { if (id == null) { return(this.NotFound()); } var postComment = await this.context.PostComments .Include(x => x.Post) .SingleOrDefaultAsync(m => m.Id == id); if (postComment == null || !this.userPermissions.CanEditPostComment(postComment)) { return(this.NotFound()); } if (this.ModelState.IsValid) { postComment.Text = model.Text; postComment.Modified = DateTime.UtcNow; await this.context.SaveChangesAsync(); return(this.RedirectToAction("Details", "Posts", new { id = postComment.PostId })); } this.ViewBag.Post = postComment.Post; return(this.View(model)); }
public async Task <IActionResult> Create(Guid?postId, PostCommentEditModel model) { if (postId == null) { return(this.NotFound()); } var post = await this.context.Posts .SingleOrDefaultAsync(m => m.Id == postId); if (post == null) { return(this.NotFound()); } var user = await this.userManager.GetUserAsync(this.HttpContext.User); if (this.ModelState.IsValid) { var now = DateTime.UtcNow; var comment = new PostComment { PostId = post.Id, CreatorId = user.Id, Created = now, Modified = now, Text = model.Text }; this.context.Add(comment); await this.context.SaveChangesAsync(); return(this.RedirectToAction("Details", "Posts", new { id = post.Id })); } this.ViewBag.Post = post; return(this.View(model)); }
// GET: PostComments/Edit/5 public async Task <IActionResult> Edit(Guid?id) { if (id == null) { return(this.NotFound()); } var postComment = await this.context.PostComments .Include(x => x.Post) .SingleOrDefaultAsync(m => m.Id == id); if (postComment == null || !this.userPermissions.CanEditPostComment(postComment)) { return(this.NotFound()); } var model = new PostCommentEditModel { Text = postComment.Text }; this.ViewBag.Post = postComment.Post; return(this.View(model)); }