public async Task <IActionResult> Create(CreateCommentsInputModel createCommentsInputModel) { if (this.ModelState.IsValid) { var parentId = createCommentsInputModel.ParentId == 0 ? (int?)null : createCommentsInputModel.ParentId; var commentsServiceModel = AutoMapperConfig.MapperInstance.Map <CommentsServiceModel>(createCommentsInputModel); commentsServiceModel.UserId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.commentsService.CreateCommentsAsync(commentsServiceModel, parentId); } return(this.RedirectToAction(nameof(this.Post))); }
public async Task <IActionResult> Create(CreateCommentsInputModel input) { var parentId = input.ParentId == 0 ? null : input.ParentId; // defense from users foolishness if (parentId.HasValue) { if (!this.commentsService.IsInPostId(parentId.Value, input.PostId)) { return(this.BadRequest()); } } var userId = this.User.FindFirstValue(ClaimTypes.NameIdentifier); await this.commentsService.Create(input.PostId, input.Content, userId, parentId); return(this.RedirectToAction("ById", "Posts", new { id = input.PostId })); }