示例#1
0
        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 }));
        }
示例#2
0
        public IActionResult Edit(int id)
        {
            var reply = _replyService.GetById(id);
            var model = new ReplyEditModel
            {
                Id           = reply.Id,
                ReplyContent = reply.Content
            };

            return(View(model));
        }
示例#3
0
        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);
            }
        }