public async Task <IActionResult> Comment(CommentOnConcertServiceModel commentModel) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var userId = this.userManager.GetUserId(this.User); commentModel.UserId = userId; var sanitizer = new HtmlSanitizer(); var sanitized = sanitizer.Sanitize(commentModel.Content); commentModel.Content = sanitized; var success = await this.userService.PostCommentAsync(commentModel); if (success) { return(this.RedirectToAction("Details", "Concerts", new { id = commentModel.ConcertId })); } return(this.BadRequest()); }
public async Task <bool> PostCommentAsync(CommentOnConcertServiceModel model) { if (model == null) { return(false); } var comment = new Comment { UserId = model.UserId, ConcertId = model.ConcertId, Content = model.Content }; this.db.Comments.Add(comment); await this.db.SaveChangesAsync(); return(true); }