public async Task <IActionResult> PostComment(string commentBody, string puzzleId) { if (!int.TryParse(puzzleId, out int puzzleIdI)) { return(Json(new { success = false, error = "Invalid puzzle ID." })); } Puzzle puzzle = await puzzleRepository.GetAsync(puzzleIdI); bool success = false; Comment comment = null; if (puzzle != null) { comment = new Comment(await counterRepository.GetAndIncreaseAsync(Counter.COMMENT_ID), (await loginHandler.LoggedInUserIdAsync(HttpContext)).Value, commentBody, null, puzzleIdI, false, DateTime.UtcNow); success = await commentRepository.AddAsync(comment); } if (success) { Notification notificationForParentAuthor = new Notification(Guid.NewGuid().ToString(), puzzle.Author, "You received a comment on your puzzle.", false, string.Format("/Puzzle/{0}?comment={1}", comment.PuzzleID, comment.ID), DateTime.UtcNow); await notificationRepository.AddAsync(notificationForParentAuthor); return(Json(new { success = true })); } else { return(Json(new { success = false, error = "Could not post comment." })); } }
public async Task <CommentResponse> SaveAsync(Comment comment, int publicationId, int userId) { var existingPublication = await _publicationRepository.FindById(publicationId); if (existingPublication == null) { return(new CommentResponse("Publication not found")); } var existingUser = await _userCommonRepository.FindById(userId); if (existingUser == null) { return(new CommentResponse("User not found")); } comment.Publication = existingPublication; comment.User = existingUser; try { await _commentRepository.AddAsync(comment); await _unitOfWork.CompleteAsync(); return(new CommentResponse(comment)); } catch (Exception ex) { return(new CommentResponse( $"An error ocurred while saving the comment: {ex.Message}")); } }
/// <inheritdoc /> public async Task <Guid> CreateAsync(string token, Guid deviceId, string comment) { if (string.IsNullOrWhiteSpace(token)) { _logger.LogError("Token is empty"); throw new ArgumentNullException(nameof(token)); } if (await _deviceRepository.HasAsync(deviceId)) { var user = await _httpService.GetCurrentUser(token); return(await _commentRepository.AddAsync(new Comment() { Message = comment, UserId = user.Id, UserName = $"{user.GivenName} {user.Surname}", CreateOn = DateTime.UtcNow, DeviceId = deviceId })); } else { throw new ArgumentException(nameof(deviceId)); } }
public async Task HandleAsync(CreateComment command) { if (!await _projectRepository.ExistsAsync(command.ProjectId)) { throw new ProjectNotFoundException(command.ProjectId); } if (!await _issueRepository.ExistsAsync(command.IssueId)) { throw new IssueNotFoundException(command.IssueId); } if (command.AuthorId != _appContext.Identity.Id && !_appContext.Identity.IsAdmin) { throw new InvalidRoleException(_appContext.Identity.Id, _appContext.Identity.Role, "Admin"); } var commentCount = await _commentRepository.GetCommentCountOfIssue(command.IssueId); var commentId = $"{command.IssueId}-{commentCount + 1}"; var comment = new Comment(commentId, command.IssueId, command.ProjectId, command.AuthorId, command.Body, DateTime.Now, new List <Reaction>()); await _commentRepository.AddAsync(comment); await _messageBroker.PublishAsync(new CommentCreated(commentId, comment.IssueId, comment.ProjectId)); }
public async Task <IActionResult> Vote(int questionnaireId, int questionId, int answerId, string comment) { var userId = userManager.GetUserId(User); Comment c = null; if (!string.IsNullOrWhiteSpace(comment)) { c = new Comment() { CommentValue = comment, UserId = userId }; await commentRepository.AddAsync(c); } var answer = new Answer() { QuestionId = questionId, QuestionnaireId = questionnaireId, PossibleAnswerId = answerId, UserId = userId, CommentId = c?.Id }; await answerRepository.Add(answer); await unitOfWork.CommitAsync(); // var nextQuestionId = await NextQuestionId(questionnaireId, questionId); var nextQuestionId = await questionnaireRepository.NextQuestionId(questionnaireId, questionId); return(RedirectToAction("Question", new { id = nextQuestionId ?? -1 })); }
public async Task <Tuple <bool, string, Comment> > Add(AddCommentViewModel commentViewModel, int currentUser) { try { var comment = _mapper.Map <Comment>(commentViewModel); comment.Level = 1; await _commentRepository.AddAsync(comment); await _unitOfWork.Commit(); await _commentDetailRepository.AddAsync(new CommentDetail { CommentID = comment.ID, UserID = comment.UserID, Seen = true }); await _unitOfWork.Commit(); var alert = await AlertComment(comment.TaskID, comment.UserID, commentViewModel.ClientRouter); var task = await _taskRepository.FindByIdAsync(comment.TaskID); if (!currentUser.Equals(task.CreatedBy)) { alert.Item1.Add(task.CreatedBy); var listUsers = alert.Item1.Where(x => x != currentUser).Distinct().ToList(); await _notificationService.Create(new CreateNotifyParams { AlertType = AlertType.PostComment, Message = alert.Item2, Users = listUsers, TaskID = comment.TaskID, URL = alert.Item3, UserID = comment.UserID }); await _hubContext.Clients.All.SendAsync("ReceiveMessage", listUsers, "message"); return(Tuple.Create(true, string.Join(",", listUsers.ToArray()), comment)); } else { return(Tuple.Create(true, string.Empty, comment)); } } catch (Exception) { return(Tuple.Create(false, string.Empty, new Comment())); } }
public async Task Consume(ConsumeContext <NewCommentModel> context) { var commentId = await _repository.AddAsync(context.Message); _logger.LogInformation("Consume new comment. Comment saved with id: {Id}", commentId); await context.RespondAsync <SavedCommentIdModel>(new { Id = commentId }); }
public async Task <Comment> CreateCommentAsync(Comment model) { var r = await _commentRepository.AddAsync(model); await _commentRepository.SaveAsync(); return(r); }
public async Task CreateNewComment(CommentViewModel comment) { await repository.AddAsync(new Comment { CommenterId = comment.Commenter.Id, Content = comment.Content, VideoId = comment.Video.Id }); }
public async Task <IActionResult> Post([FromBody] CommentDTO commentToAdd) { logger.LogInformation("Calling post for the following object: {@0} ", commentToAdd); Comment insertedComment = await repository.AddAsync(mappingProvider.Map <Comment>(commentToAdd)); CommentDTO commentToReturn = mappingProvider.Map <CommentDTO>(insertedComment); return(CreatedAtRoute("GetComment", new { id = commentToReturn.Id }, commentToReturn)); }
public async Task <ActionResult <Comment> > Post(CommentInput input) { var comment = new Comment(input); _repo.AddAsync(comment); await _repo.SaveAsync(); return(comment); }
public async Task AddCommentAsync(Guid userID, string content, Guid productID) { var user = await _userRepoistory.GetAsync(userID); var product = await _productRepository.GetAsync(productID); var comment = new Comment(content, user, product); await _commentRepository.AddAsync(comment); }
public async Task AddAsync(string content, Guid userId, Guid postId) { var user = await _userRepository.GetAsync(userId); var post = await _postRepository.GetAsync(postId); var comment = new Comment(content, user, post); await _commentRepository.AddAsync(comment); }
public async Task <CommentForQuestionGetModel> CommentOnQuestionAsync(CommentOnQuestionCreateModel commentModel) { var question = (await _questionRepository.GetQuestionWithCommentsAsync(commentModel.QuestionId)) ?? throw new EntityNotFoundException(nameof(Question), commentModel.QuestionId); var user = await _userRepository.GetByIdAsync(commentModel.UserId); var commentOrderNumber = question .Comments .Select(c => c.OrderNumber) .OrderByDescending(c => c) .FirstOrDefault() + 1; var comment = Comment.Create(user, commentModel.Body, commentOrderNumber, _limits); question.Comment(comment); await _commentRepository.AddAsync(comment); await _uow.SaveAsync(); return(_mapper.Map <CommentForQuestionGetModel>(comment)); }
public async Task <DomainComment> AddCommentAsync(DomainComment domainComment) { ProjectEntity projectEntity = await _projectRepository.GetAsync(domainComment.ProjectId); CheckProject(projectEntity, domainComment.UserId); CommentEntity commentEntity = _mapper.Map <DomainComment, CommentEntity>(domainComment); await _commentRepository.AddAsync(commentEntity); return(CreateDomainComment(commentEntity, projectEntity.UserId)); }
public Task <IActionResult> Add(Comment model) { return(Task.Factory.StartNew <IActionResult>(() => { if (!ModelState.IsValid) { return Json(ExcutedResult.FailedResult("数据验证失败")); } CommentRepository.AddAsync(model, false); return Json(ExcutedResult.SuccessResult()); })); }
public async Task <IResultModel> Add(CommentAddModel model) { var entity = _mapper.Map <CommentEntity>(model); //if (await _repository.Exists(entity)) //{ //return ResultModel.HasExists; //} var result = await _repository.AddAsync(entity); return(ResultModel.Result(result)); }
public async Task <Response <bool> > Handle(AddCommentCommand request, CancellationToken cancellationToken) { var comment = new Comment { CreatedDate = DateTime.UtcNow, senderId = request.Userid, Description = request.Description, BookId = request.bookId }; await commentRepo.AddAsync(comment); return(Response.Ok()); }
public async Task <IActionResult> PostComment(int articleId, CommentDto comment) { var commentToInsert = _mapper.Map <Comment>(comment); commentToInsert.ArticleId = articleId; commentToInsert.UserId = CurrentUser.Id; await _commentRepository.AddAsync(commentToInsert); await _unitOfWork.SaveChangesAsync(); var comments = await LoadComments(articleId); return(Ok(comments)); }
public async Task <CommentResponse> SaveAsync(Comment comment) { try { await _commentRepository.AddAsync(comment); await _unitOfWork.CompleteAsync(); return(new CommentResponse(comment)); } catch (Exception ex) { return(new CommentResponse($"An error ocurred while saving the comment: {ex.Message}")); } }
public async Task <CommentResponse> SaveAsync(Comment category) { try { await categoryRepository.AddAsync(category); await unitOfWork.CompleteAsync(); return(new CommentResponse(category)); } catch (Exception ex) { return(new CommentResponse($"Error occured when saving comment: {ex.Message}")); } }
public async Task <IActionResult> AddComment(Comment comment, int id, int userId) { comment.MusicId = id; comment.UserDetailId = userId; var user = await _detailRepository.GetByIdAsync(userId); var music = await _musicRepository.GetByIdAsync(id); user.TotalComments++; user.TotalScore += _detailRepository.GiveRandomScore(); music.TotalComments++; await _commentRepository.AddAsync(comment); return(RedirectToAction("Index", "Music")); }
public async Task <CommentResponse> SaveAsync(int ownerId, int veterinaryId, Comment comment) { var existingOwner = await _ownerProfileRepository.FindById(ownerId); var existingVeterinary = await _veterinaryProfileRepository.FindById(veterinaryId); if (existingOwner == null) { return(new CommentResponse("Owner not found")); } if (existingVeterinary == null) { return(new CommentResponse("Veterinary not found")); } try { bool attended = false; IEnumerable <Appointment> appointments = await _appointmentRepository.ListByScheduleId(ownerId); if (appointments != null) { appointments.ToList().ForEach(appointment => { if (appointment.VeterinaryId == veterinaryId && appointment.OwnerId == ownerId) { attended = true; } }); } if (!attended) { return(new CommentResponse("Solo puedes calificar una veterinaria en la cual tu mascota haya sido atendida")); } comment.OwnerProfileId = ownerId; comment.VeterinaryProfileId = veterinaryId; await _commentRepository.AddAsync(comment); await _unitOfWork.CompleteAsync(); return(new CommentResponse(comment)); } catch (Exception ex) { return(new CommentResponse($"An error ocurred while saving comment: {ex.Message}")); } }
public async Task <SaveCommentResponse> SaveAsync(Comment comment) { try { await _commentRepository.AddAsync(comment); await _unitOfWork.CompleteAsync(); return(new SaveCommentResponse(comment)); } catch (Exception ex) { // Do some logging stuff return(new SaveCommentResponse($"An error occurred when saving the comment: {ex.Message}")); } }
public async Task <IActionResult> Create([FromBody] CommentRequest model) { if (!ModelState.IsValid) { return(BadRequest(ErrorResponse.InvalidPayload)); } var comment = _mapper.Map <CommentEntity>(model); comment.DateCreated = DateTime.Now; await _commentRepository.AddAsync(comment); await _unitOfWork.SaveChangesAsync(); return(Ok()); }
public async Task <ActionResult> AddComment([FromBody] CommentRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var commentEntity = _mapper.Map <CommentEntity>(request); commentEntity.senderId = userId; await _commentRepository.AddAsync(commentEntity); return(Ok(new ResultModel { result = true })); }
public async Task <Guid> AddCommentAsync(Guid postId, SaveCommentModel model) { ArgumentGuard.NotEmpty(postId, nameof(postId)); ArgumentGuard.NotNull(model, nameof(model)); await _validatorFactory.ValidateAsync(model); var commentEntity = new CommentEntity { Id = Guid.NewGuid(), Content = model.Content, AuthorId = _userContext.UserId, PostId = postId, CreatedDateUtc = DateTime.UtcNow, LastModfiedById = _userContext.UserId, }; return(await _commentRepository.AddAsync(commentEntity)); }
public async Task <IActionResult> CreateComment(CourseCreateCommnet model, CancellationToken cancellationToken) { CustomUser user = await userManager.GetUserAsync(User); Comment comment = new Comment { Body = model.Body, CoourseId = model.CourseId, IsDeleted = false, IsReadedByAdmin = false, Name = user.ShowUserName, User = user, UserId = user.Id, CreateTime = DateTime.Now }; await commentRepository.AddAsync(comment, cancellationToken); return(RedirectToAction(nameof(GetComments), new { model.CourseId, model.CurrentPageNumber })); }
public async Task <int> AddCommentToDB(CommentVM comment) { var user = _applicationUserRepository.GetUserByUserName(comment.UserId); comment.UserId = user.Id; var cmt = _mapper.Map <Comment>(comment); await _commentRepository.AddAsync(cmt); if (comment.Rating > 0) { var listCmt = await _commentRepository.GetListCommentByProductId(comment.ProductId); //update product rating var rank = await _productRankRepository.GetSingleByIDAsync(comment.ProductId); rank.Rate = listCmt.Average(m => m.Rating); await _productRankRepository.UpdateAsync(rank); } return(await _unitOfWork.SaveAsync()); }
public async Task <Outcome <int> > AddCommentAsync(CommentAddRequest request) { var comment = await _repository.GetAsync(request.Id); if (comment != null) { return(Outcome.Fail <int>(Status409Conflict, DuplicateCommentId)); } comment = CommentMappingHelper.MapToComment(request); await _repository.AddAsync(comment); await _repository.SaveAsync(); // Publish message to ServiceBus to trigger function to // get comment tone await _queueClient.SendAsync(CreateCommentMessage(request)); return(Outcome.Success(comment.Id)); }