コード例 #1
0
ファイル: ReplyController.cs プロジェクト: hpp1221/redRen
        public async Task <IActionResult> Edit(ReplyEditViewModel model)
        {
            model.Content     = model.Content.Trim();
            ViewData["Error"] = true;
            if (model != null)
            {
                model.Content = model.Content.Trim();
            }
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var reply = await _replyRepo.FindAsync(p => p.ReplyId == model.ReplyId);

            if (reply == null)
            {
                throw new Exception("回复找不到,或已被删除");
            }
            reply.Content        = model.Content;
            reply.UpdateDateTime = DateTime.Now;
            var success = await _replyRepo.UpdateAsync(reply);

            if (success)
            {
                ViewData["Error"] = false;
                return(Redirect($"/Topic/Index/{reply.Topic_Id}#{reply.ReplyId}"));
            }
            else
            {
                ModelState.AddModelError("", "保存失败,请稍后重试");
                return(View(model));
            }
        }
コード例 #2
0
        public async Task <IActionResult> Edit(ReplyEditViewModel input)
        {
            if (!this.User.IsInRole(GlobalConstants.AdministratorRoleName) &&
                !this.User.IsInRole(GlobalConstants.ModeratorRoleName))
            {
                var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier);

                if (userId != input.UserId)
                {
                    return(this.BadRequest());
                }
            }

            if (!this.ModelState.IsValid)
            {
                var viewModel = this.repliesService.GetById <ReplyEditViewModel>(input.Id);

                return(this.View(viewModel));
            }

            var replyId = await this.repliesService.EditAsync(input.Id, input.Content);

            if (replyId == null)
            {
                return(this.NotFound());
            }

            this.TempData["InfoMessage"] = "Reply edited successfully!";
            return(this.RedirectToAction("ByName", "Posts", new { name = input.PostUrl }));
        }
コード例 #3
0
ファイル: ReplyController.cs プロジェクト: hpp1221/redRen
        /// <summary>
        /// 编辑回复
        /// </summary>
        /// <param name="id">回复ID</param>
        /// <returns></returns>
        public async Task <IActionResult> Edit(int id)
        {
            ViewData["Error"] = false;
            var reply = await _replyRepo.FindAsync(p => p.ReplyId == id);

            if (reply == null)
            {
                throw new Exception("回复找不到,或已被删除");
            }
            var replyViewModel = new ReplyEditViewModel()
            {
                ReplyId = reply.ReplyId,
                Content = reply.Content
            };

            return(View(replyViewModel));
        }