public async Task <IActionResult> EditReply(ReplyEditModel model) { var reply = _replyService.GetById(model.Id); reply.Content = model.ReplyContent; await _replyService.Edit(reply); return(RedirectToAction("Index", "Post", new { id = reply.Post.Id })); }
public IActionResult Edit(int id) { var reply = _replyService.GetById(id); var model = new ReplyEditModel { Id = reply.Id, ReplyContent = reply.Content }; return(View(model)); }
public async Task Edit_PostReply_Correctly_By_EditPostReply() { var options = new DbContextOptionsBuilder <ApplicationDbContext>() .UseInMemoryDatabase(databaseName: "Edit_Post").Options; //Arrange using (var ctx = new ApplicationDbContext(options)) { ctx.PostReplies.Add(new PostReply { Id = 221, Content = "First Post Reply" }); ctx.PostReplies.Add(new PostReply { Id = 123, Content = "Second Post Reply" }); ctx.SaveChanges(); } //Act using (var ctx = new ApplicationDbContext(options)) { var replyService = new ReplyService(ctx); var newReply = new ReplyEditModel { ReplyContent = "Updated Content" }; var reply = ctx.PostReplies.Find(221); reply.Content = newReply.ReplyContent; await replyService.Edit(reply); //Assert Assert.AreEqual(newReply.ReplyContent, reply.Content); } }