Beispiel #1
0
        public ActionResult Edit(int id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            var reply = _postRepositories.GetByReplyId(id);

            if (reply == null)
            {
                return(HttpNotFound());
            }
            var model = new EditReplyModel
            {
                Id = reply.Id,
                NewReplyContent = reply.Content,
                PostId          = reply.Post_Id,
                UserId          = reply.User_Id,
                DateCreated     = reply.Created,
                ForumName       = reply.Post.Forum.Title,
                PostContent     = reply.Post.Content,
                PostTitle       = reply.Post.Title
            };

            return(View(model));
        }
Beispiel #2
0
 private PostReply BuildEditPostModel(EditReplyModel model)
 {
     return(new PostReply
     {
         Id = model.Id,
         Content = model.NewReplyContent,
         Post_Id = model.PostId,
         User_Id = model.UserId,
         Created = model.DateCreated
     });
 }
Beispiel #3
0
        public async Task <ActionResult> EditReply([Bind(Include = "Id, NewReplyContent, PostId, UserId, DateCreated")] EditReplyModel model)
        {
            if (ModelState.IsValid)
            {
                var reply = BuildEditPostModel(model);
                await _postRepositories.UpdateReplyContent(reply);

                return(RedirectToAction("Index", "Post", new { id = model.PostId }));
            }
            return(View(model));
        }
        public async Task <ActionResult> Update(EditReplyModel model)
        {
            if (model.AuthorId != _contextService.CurrentAccount.AccountId)
            {
                return(Json(new { success = false, errorMsg = "您不是回复的作者,不能编辑该回复。" }));
            }

            var result = await _commandService.SendAsync(new ChangeReplyBodyCommand(model.Id, model.Body));

            if (result.Status != AsyncTaskStatus.Success)
            {
                return(Json(new { success = false, errorMsg = result.ErrorMessage }));
            }

            return(Json(new { success = true }));
        }
Beispiel #5
0
        public async Task <IActionResult> Edit(EditReplyModel model)
        {
            if (!await this.postService.DoesItExist(model.PostId))
            {
                return(this.NotFound());
            }

            var serviceModel = new EditReplyServiceModel
            {
                ReplyId = model.ReplyId,
                Content = model.Content,
            };

            await this.replyService.EditReplyContent(serviceModel);

            return(this.RedirectToAction("Index", "Post", new { id = model.PostId }));
        }
Beispiel #6
0
        public async Task <ActionResult> Update(EditReplyModel model)
        {
            var currentAccount = _contextService.GetCurrentAccount(HttpContext);

            if (model.AuthorId != currentAccount.AccountId)
            {
                return(Json(new { success = false, errorMsg = "您不是回复的作者,不能编辑该回复。" }));
            }

            var result = await _commandService.ExecuteAsync(new ChangeReplyBodyCommand(model.Id, model.Body));

            if (result.Status == CommandStatus.Failed)
            {
                return(Json(new { success = false, errorMsg = result.Result }));
            }

            return(Json(new { success = true }));
        }
Beispiel #7
0
        public async Task <ActionResult> Update(EditReplyModel model)
        {
            if (model.AuthorId != _contextService.CurrentAccount.AccountId)
            {
                return(Json(new { success = false, errorMsg = "您不是回复的作者,不能编辑该回复。" }));
            }

            AsyncTaskResult <CommandResult> asyncTaskResult = await _commandService.ExecuteAsync(new ChangeReplyBodyCommand(model.Id, model.Body), CommandReturnType.EventHandled);

            var result = asyncTaskResult.Data;

            if (result.Status == CommandStatus.Failed)
            {
                return(Json(new { success = false, errorMsg = result.ErrorMessage }));
            }

            return(Json(new { success = true }));
        }
        public async Task GetByIdGetsTheRightEntity()
        {
            var model = new EditReplyModel
            {
                AuthorName = this.testPost2.Author.UserName,
                ReplyId    = this.testReply2.Id,
                PostId     = this.testReply2.PostId,
                Content    = this.testReply2.Content,
            };

            var result = await this.service.GetReplyById <EditReplyModel>(this.testReply2.Id);

            var expected = await JsonConvert.SerializeObjectAsync(model);

            var actual = await JsonConvert.SerializeObjectAsync(result);

            // I am serializing the objects to ensure that it Assert.Equal won't compare any
            // internal properties that I am not trying to compare in this test
            Assert.Equal(expected, actual);
        }