public ActionResult AddComment(int eventId) { var model = new AddCommentInputModel { EventId = eventId }; return(PartialView(model)); }
public async Task <ActionResult <CommentViewModel> > Edit(AddCommentInputModel inputModel) { var user = await this.userManager.GetUserAsync(this.User); var viewModel = await this.commentsService.EditAsync(inputModel); viewModel.ApplicationUserUserName = user.UserName; return(viewModel); }
public async Task <IActionResult> Add(AddCommentInputModel inputModel) { if (ModelState.IsValid) { User user = await this.userManager.GetUserAsync(User); inputModel.Author = user; await this.commentService.AddComment(inputModel); } return(this.Redirect($"/Club/Details/{inputModel.ClubId}#{inputModel.PostId}")); }
public async Task <IActionResult> Add(AddCommentInputModel input) { if (!this.ModelState.IsValid) { return(this.Redirect($"/Recipes/RecipeDetails/{input.Id}")); } var userId = this.userManager.GetUserId(this.User); await this.commentsService.AddAsync(input.Id, input.Content, userId); this.TempData["InfoMessage"] = GlobalConstants.SuccessAddedComment; return(this.Redirect($"/Recipes/RecipeDetails/{input.Id}")); }
public async Task <ActionResult <CommentResponseModel> > AddComment(AddCommentInputModel model) { var user = await this.userManager.GetUserAsync(this.User); var userId = await this.userManager.GetUserIdAsync(user); model.UserId = userId; model.Description = new HtmlSanitizer().Sanitize(model.Description); if (!this.ModelState.IsValid || string.IsNullOrWhiteSpace(model.UserId) || string.IsNullOrWhiteSpace(model.Description)) { return(this.RedirectToAction("DetailedPost", "Posts", new { id = model.PostId })); } var commentId = await this.commentsService.AddCommentToPostAsync(model); var response = await this.commentsService.GetCommentByIdAsync <CommentResponseModel>(commentId); return(response); }
public async Task <Comment> AddComment(AddCommentInputModel inputModel) { Post post = await this.postService.GetPostById(inputModel.PostId); Comment comment = new Comment() { Content = inputModel.Content, Author = inputModel.Author, AuthorId = inputModel.Author.Id, Post = post, PostId = post.Id, Date = DateTime.Now }; await this.dbContext.Comments.AddAsync(comment); await this.dbContext.SaveChangesAsync(); return(comment); }
public async Task AddComment(AddCommentInputModel model) { var currentUser = await this.db.Users.FirstOrDefaultAsync(x => x.UserName == model.Username); var comment = new ProductComment { ApplicationUserId = currentUser?.Id, Email = model.Email, Content = model.SanitizedContent, CreatedOn = DateTime.UtcNow, PhoneNumber = model.PhoneNumber, ProductId = model.ProductId, UserFullName = model.FullName, ParentCommentId = model.ParentId, }; await this.db.ProductComments.AddAsync(comment); await this.db.SaveChangesAsync(); }
public async Task <CommentViewModel> AddAsync(AddCommentInputModel inputModel) { var comment = new Comment { ApplicationUserId = inputModel.ApplicationUserId, Content = inputModel.Content, ReviewId = inputModel.ReviewId, }; await this.commentsRepository.AddAsync(comment); await this.commentsRepository.SaveChangesAsync(); var viewModel = new CommentViewModel { Id = comment.Id, Content = comment.Content, CreatedOn = comment.CreatedOn, }; return(viewModel); }
public async Task <CommentViewModel> EditAsync(AddCommentInputModel inputModel) { var comment = await this.commentsRepository.GetByIdWithDeletedAsync(inputModel.Id); if (comment == null) { throw new ArgumentNullException(InvalidIdExceptionMessage); } comment.Content = inputModel.Content; this.commentsRepository.Update(comment); await this.commentsRepository.SaveChangesAsync(); var viewModel = new CommentViewModel { Id = comment.Id, Content = comment.Content, CreatedOn = comment.CreatedOn, }; return(viewModel); }