public async Task <IActionResult> Edit(Guid id) { Guid? loginUserId = this.User.GetUserId(); Comment comment = await this.commentService.GetByIdAsync(id); if (comment == null || comment.IsDelete) { return(NotFound()); } else if (loginUserId == null || loginUserId.Value != comment.PersonId) { return(this.Forbid()); } else { CommentEditModel model = new CommentEditModel { Id = comment.Id, Content = comment.HtmlContent, ParentId = comment.ParentId, PostId = comment.PostId, PostType = (await this.postService.GetPostTypeAsync(comment.PostId)).Value }; return(View(model)); } }
public async Task <IActionResult> Edit(string id, CommentInputModel commentInput) { var existsComment = this.commentsService .Exists(x => x.Id == id); if (!existsComment) { return(this.NotFound()); } if (!this.ModelState.IsValid) { var comment = new CommentEditModel() { Id = id, CommentInput = commentInput, }; return(this.View(comment)); } await this.commentsService.EditAsync(id, commentInput); this.TempData[GlobalConstants.MessageKey] = $"Successfully edited comment!"; return(this.RedirectToAction("Details", "Posts", new { area = "Forum", id = commentInput.PostId })); }
public ActionResult Edit(CommentEditModel model) { CommentSvc.Update(model.id, model.phonenum, model.email, model.context); return(Json(new AjaxResult { status = "ok" })); }
public ActionResult Edit(CommentEditModel model) { if (this.ModelState.IsValid) { var userId = this.User.Identity.GetUserId(); var comment = this.Data.Comments.GetById(model.Id); comment.Content = model.Content; this.Data.Comments.Update(comment); this.Data.SaveChanges(); if (model.Reason != null) { var commentUpdate = new CommentUpdate { AuthorId = userId, CommentId = comment.Id, Reason = model.Reason }; this.Data.CommentUpdates.Add(commentUpdate); this.Data.SaveChanges(); } var viewModel = Mapper.Map <CommentViewModel>(comment); viewModel.IsUpdating = true; return(this.PartialView("_CommentDetailPartial", viewModel)); } return(this.JsonError("Content is required")); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var userId = this.User.Identity.GetUserId(); var comment = this.Data.Comments.GetById(id); if (comment == null) { return(this.HttpNotFound()); } if (comment.AuthorId != userId && !this.User.IsModerator() && !this.User.IsAdmin()) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var model = new CommentEditModel { Id = comment.Id, Content = comment.Content }; return(this.PartialView(model)); }
public async Task <ActionResult> SaveComment(CommentEditModel model) { if (!ModelState.IsValid) { return(PartialView("_CommentEdit", model)); } var item = await _itemDbCommand.FindAsync(model.ItemId); if (item == null) { return(HttpNotFound()); } var comment = await _commentDbCommand.FindAsync(model.CommentId); if (comment == null) { comment = item.NewComment(LogonUser); Mapper.Map(model, comment); } else { comment.LastModifiedDateTime = DateTime.Now; } await _commentDbCommand.SaveAsync(comment); return(RedirectToAction("Item", new { id = model.ItemId })); }
public virtual PartialViewResult Edit(CommentEditModel model) { var editCommentId = FullContext.Value.EntityId.Value; var commentsTarget = FullContext.GetCommentsTarget(); var targetEntityId = commentsTarget.EntityId.Value; if (!ModelState.IsValid) { return(OverView(editCommentId)); } var comment = _commentsService.Get(editCommentId); if (!_commentsService.CanEdit(comment, _intranetUserService.GetCurrentUserId())) { return(OverView(editCommentId)); } var editDto = MapToEditDto(model, editCommentId); var command = new EditCommentCommand(FullContext, editDto); _commandPublisher.Publish(command); switch (commentsTarget.Type.ToInt()) { case int type when ContextExtensions.HasFlagScalar(type, ContextType.Activity | ContextType.PagePromotion): var activityCommentsInfo = GetActivityComments(targetEntityId); return(OverView(activityCommentsInfo)); default: return(OverView(comment.ActivityId)); } }
public async Task <CommentsOverviewModel> Edit(CommentEditModel model) { var comment = await _commentsService.GetAsync(model.Id); if (!_commentsService.CanEdit(comment, await _intranetMemberService.GetCurrentMemberIdAsync())) { return(await _commentsHelper.OverViewAsync(model.Id)); } var editDto = MapToEditDto(model, model.Id); var command = new EditCommentCommand(model.EntityId, model.EntityType, editDto); _commandPublisher.Publish(command); await OnCommentEditedAsync(model.Id, model.EntityType); switch (model.EntityType) { case IntranetEntityTypeEnum type when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events): var activityCommentsInfo = GetActivityComments(model.EntityId); return(await _commentsHelper.OverViewAsync(activityCommentsInfo.Id, activityCommentsInfo.Comments, activityCommentsInfo.IsReadOnly)); default: return(await _commentsHelper.OverViewAsync(comment.ActivityId)); } }
public async Task <IActionResult> Create([FromBody] CommentEditModel model) { CommentView comment = await this.commentService.InsertAsync(model, this.User.GetUserId().Value); PersonView person = await this.personService.GetCurrentPersonViewAsync(); return(ViewComponent(typeof(CommentItemViewComponent), new { pLoginPerson = person, pCommentView = comment })); }
public async Task Update(string id, CommentEditModel model) { Comment comment = this.context.Comments.Find(id); comment.Text = model.Text; this.context.Comments.Update(comment); await this.context.SaveChangesAsync(); }
public ActionResult Edit(CommentEditModel m) { if (ModelState.IsValid) { m.Save(); SuccessMessage(Piranha.Resources.Comment.MessageSaved); ModelState.Clear(); } return(View(m)); }
public async Task <IActionResult> Edit(CommentEditModel model) { if (ModelState.IsValid) { try { if (model.Id == null) { throw new Exception("评论ID不能为空"); } Guid? loginUserId = this.User.GetUserId(); Comment comment = await this.commentService.GetByIdAsync(model.Id.Value); if (comment == null || comment.IsDelete) { throw new Exception("该评论不存在,或已被删除"); } else if (loginUserId == null || loginUserId.Value != comment.PersonId) { throw new Exception("没有该操作的权限"); } else if (string.IsNullOrWhiteSpace(model.Content)) { throw new Exception("内容不能为空"); } else { string htmlContent = this.htmlService.ClearHtml(model.Content); string textContent = this.htmlService.HtmlToText(htmlContent); if (string.IsNullOrWhiteSpace(htmlContent)) { throw new Exception("内容不能为空"); } else { await this.commentService.ModifyAsync(comment.Id, htmlContent, textContent); return(Json(AjaxResult.CreateDefaultSuccess())); } } } catch (ModelException ex) { return(this.Json(ex.ToAjaxResult())); } catch (Exception ex) { return(this.Json(AjaxResult.CreateByMessage(ex.Message, false))); } } else { return(this.Json(ModelState.ToAjaxResult())); } }
public async Task <IActionResult> Put(string id, CommentEditModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } await this.commentService.Update(id, model); return(this.Ok()); }
public async Task <IActionResult> Delete(CommentEditModel input) { if (!this.ModelState.IsValid) { return(this.View(input)); } await this.commentsService.Delete(input); return(this.Redirect($"/Forum/Forum")); }
public ActionResult _Comment(long commentedObjectId, long ownerId, string tenantTypeId, string originalAuthor = null) { CommentEditModel commentModel = new CommentEditModel { CommentedObjectId = commentedObjectId, OwnerId = ownerId, TenantTypeId = tenantTypeId }; return(View(commentModel)); }
public async Task EditAsync(CommentEditModel commentModel) { var comment = await GetCommentOnEditOrDeleteAsync(commentModel.ParentQuestionId, commentModel.ParentAnswerId, commentModel.CommentId); var user = await _userRepository.GetUser <User>(commentModel.UserId); comment.Edit(user, commentModel.Body, _limits); await _uow.SaveAsync(); // @nl: raise an event? }
public async Task Delete(CommentEditModel input) { var comment = this.commentsRepository .All() .FirstOrDefault(x => x.Id == input.Id); comment.IsDeleted = true; comment.DeletedOn = DateTime.UtcNow; this.commentsRepository.Update(comment); await this.commentsRepository.SaveChangesAsync(); }
public async Task Edit(CommentEditModel input) { var comment = this.commentsRepository .All() .FirstOrDefault(x => x.Id == input.Id); comment.Content = input.Content; comment.ModifiedOn = DateTime.UtcNow; this.commentsRepository.Update(comment); await this.commentsRepository.SaveChangesAsync(); }
public async Task <IActionResult> PostChildrenCommentar(CommentEditModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var userId = this.userManager.GetUserId(this.User); await this.commentService.CreateChildrenComment(model, userId); return(this.Ok()); }
public IActionResult Edit(CommentEditModel commentEditModel, int id) { var comment = _db.Comments.Include(c => c.Post) .Include(u => u.Author) .FirstOrDefault(c => c.Id == id); var postId = comment.Post.Id; if (User.Identity.Name == comment.Author.UserName && comment.CreateDate.AddMinutes(15) >= DateTime.Now) { comment.Text = commentEditModel.CommentText; _db.SaveChanges(); } return(RedirectToAction("Index", "Comment", new { id = postId })); }
public ActionResult Delete(string id) { var m = CommentEditModel.GetById(new Guid(id)); if (m.Delete()) { SuccessMessage(Piranha.Resources.Comment.MessageDeleted); } else { ErrorMessage(Piranha.Resources.Comment.MessageNotDeleted); } return(Index()); }
public ActionResult CommentsDelete([DataSourceRequest]DataSourceRequest request, CommentEditModel comment) { if (this.ModelState.IsValid) { var originalComment = this.comments.GetAll().FirstOrDefault(a => a.Id == comment.Id); if (originalComment != null) { originalComment.IsDeleted = true; } this.comments.Update(originalComment); } return this.Json(new[] { comment }.ToDataSourceResult(request, this.ModelState)); }
public ActionResult CommentsCreate([DataSourceRequest]DataSourceRequest request, CommentEditModel comment) { if (this.ModelState.IsValid) { var newComment = new Comment { Content = comment.Content, ArticleId = comment.ArticleId }; newComment.AuthorId = this.User.Identity.GetUserId(); this.comments.Create(newComment); } return this.Json(new[] { comment }.ToDataSourceResult(request, this.ModelState)); }
public async Task Delete_WithIncorrectId_ShouldThrowException(int id) { MapperInitializer.InitializeMapper(); var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext(); await this.CreateTestComments(dbContext); var repository = new EfDeletableEntityRepository <Comment>(dbContext); var service = new CommentsService(repository); var model = new CommentEditModel(); model.Id = id; await Assert.ThrowsAsync <NullReferenceException>(() => service.Delete(model)); }
public ActionResult Edit(CommentEditModel model) { if (model != null && this.ModelState.IsValid) { var comment = this.Data.Comments.GetById(model.Id); comment.Content = model.Content; comment.IsDeleted = model.IsDeleted; this.Data.Comments.Update(comment); this.Data.SaveChanges(); return(this.RedirectToAction("All")); } return(this.View(model)); }
public IActionResult Edit(string id) { var existsComment = this.commentsService .Exists(x => x.Id == id); if (!existsComment) { return(this.NotFound()); } var comment = new CommentEditModel() { Id = id, CommentInput = this.commentsService .GetSingle <CommentInputModel>(x => x.Id == id), }; return(this.View(comment)); }
public IActionResult SaveEditingComment([FromBody] CommentEditModel model) { CommentEditReturnModel ret; if (model == null) { return(BadRequest()); } Claim idClaim = User.FindFirst("sub"); if (idClaim == null) { return(Unauthorized()); } else { ret = _commentActionService.EditComment(model.CommentId, model.Content, idClaim.Value); } return(Ok(ret)); }
public IHttpActionResult EditComment([FromBody] CommentEditModel comment, [FromUri] Guid id) { try { if (!UserAuthorize(_commentService.GetCommentById(id).AuthorId, "Moder, Admin")) { return(Unauthorized()); } var commentDto = _mapper.Map <CommentEditModel, CommentDTO>(comment); commentDto.Id = id; _commentService.EditComment(commentDto); } catch (Exception) { return(Conflict()); } return(StatusCode(HttpStatusCode.NoContent)); }
public async Task Delete_WithCorrectId_ShouldRemoveComment() { MapperInitializer.InitializeMapper(); var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext(); await this.CreateTestComments(dbContext); var repository = new EfDeletableEntityRepository <Comment>(dbContext); var service = new CommentsService(repository); var model = new CommentEditModel(); model.Id = 1; await service.Delete(model); var result = repository.AllWithDeleted().Where(p => p.Id == 1).FirstOrDefault().IsDeleted; Assert.True(result); }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var comment = this.Data.Comments.GetById(id); if (comment == null) { return(this.HttpNotFound()); } var model = new CommentEditModel { Id = comment.Id, Content = comment.Content }; return(this.PartialView(model)); }
public async Task CreateChildrenComment(CommentEditModel model, string userId) { string parentCommentId = model.ParentCommentId; Comment parentComment = this.context.Comments.Find(parentCommentId); string songId = parentComment.SongId; Song song = this.context.Songs.Find(songId); ApplicationUser user = this.context.Users.Find(userId); Comment comment = model.To <Comment>(); comment.UserId = userId; comment.SongId = songId; comment.User = user; comment.Song = song; comment.ParentComment = parentComment; comment.ParentCommentId = parentCommentId; parentComment.CommentsChildren.Add(comment); this.context.Comments.Update(parentComment); await this.context.SaveChangesAsync(); }
public async Task Edit_WithValidInput_ShouldChangeContent() { MapperInitializer.InitializeMapper(); var dbContext = ApplicationDbContextCreatorInMemory.InitializeContext(); await this.CreateTestComments(dbContext); var repository = new EfDeletableEntityRepository <Comment>(dbContext); var service = new CommentsService(repository); var viewModel = new CommentEditModel() { Id = 1, Content = "Edited", }; await service.Edit(viewModel); var comment = service.GetById <CommentEditModel>(1); Assert.Equal("Edited", comment.Content); }