public object SearchPost(string tittle) { var data = uow.Repository <Posts>().GetAll().Where(s => s.Status == EntityStatus.Active && s.PostTittle.Contains(tittle)).ToList(); var posts = new List <PostDto>(); foreach (var a in data) { var post = new PostDto(); post.Id = a.Id; post.PostTittle = a.PostTittle; post.CreateBy = a.CreateBy; post.CreateDate = a.CreateDate; foreach (var c in a.Comments) { var comment = new CommentsDto(); comment.Id = c.Id; comment.Comment = c.Comment; comment.TotalDisLike = c.TotalDisLike; comment.TotalLike = c.TotalLike; comment.CreateBy = c.CreateBy; comment.CreateDate = c.CreateDate; post.CommentsDtos.Add(comment); } posts.Add(post); } //var postData = Mapper.Map return(posts); }
/// <inheritdoc cref="ICommentsService"/> public async Task <CommentsDto> GetCommentsForPost(int?postId, string authorId, SortParametersDto sortParameters) { var comments = Table; if (postId != null) { comments = comments.Where(comment => comment.PostId == postId); } if (!string.IsNullOrWhiteSpace(authorId)) { comments = comments.Where(comment => comment.AuthorId.Equals(authorId)); } var commentsDto = new CommentsDto() { Comments = await comments.Include(x => x.Author).ToListAsync(), }; var count = commentsDto.Comments.Count; if (sortParameters == null) { return(commentsDto); } commentsDto.Comments = commentsDto.Comments.Skip((sortParameters.CurrentPage - 1) * sortParameters.PageSize).Take(sortParameters.PageSize).ToList(); commentsDto.PageInfo = new PageInfo { PageNumber = sortParameters.CurrentPage, PageSize = sortParameters.PageSize, TotalItems = count }; return(commentsDto); }
public async Task <IActionResult> PostComment([FromBody] CommentsDto commentModel) { try { if (ModelState.IsValid) { var author = _userManager.FindByIdAsync(User.FindFirst(ClaimTypes.NameIdentifier).Value).Result; var comment = new Comments() { Author = author.UserName, Body = commentModel.Body, CreateDate = DateTime.UtcNow.ToLocalTime(), // News = await _mediator.Send(new GetNewsById(newsId)) }; var result = await _mediator.Send(new AddComment(comment)); if (result) { Log.Information("Action PostComment => completed successfully "); return(Ok(comment)); } } } catch (Exception ex) { Log.Error($"Action PostComment => {ex.Message}"); } return(BadRequest()); }
public async Task <ActionResult <CommentsDto> > Put(int commentId, CommentsDto dto) { try { var oldComment = await _eventRepository.GetComment(commentId); if (oldComment == null) { return(NotFound($"Could not find Comment with id {commentId}")); } var newComment = _mapper.Map(dto, oldComment); _eventRepository.Update(newComment); if (await _eventRepository.Save()) { return(NoContent()); } } catch (Exception) { return(this.StatusCode(StatusCodes.Status500InternalServerError, "Database Failure")); } return(BadRequest()); }
public async Task <CustomApiResponse> Put([FromBody] CommentsDto entity) { var inputEntity = _mapper.Map <Comments>(entity); var result = await _commentService.Update(inputEntity); return(new CustomApiResponse(entity.Id, result ? "Succeeded" : "Failed", !result)); }
public async Task <Comment> AddComment(CommentsDto commentDto) { var mapped = _mapper.Map <Comment>(commentDto); await _context.Comments.AddAsync(mapped); await _context.SaveChangesAsync(); return(mapped); }
public async Task <IActionResult> GetComments(string app, Guid commentsId, [FromQuery] long version = EtagVersion.Any) { var result = await grainFactory.GetGrain <ICommentGrain>(commentsId).GetCommentsAsync(version); var response = CommentsDto.FromResult(result); Response.Headers["ETag"] = response.Version.ToString(); return(Ok(response)); }
public async Task <CustomApiResponse> Post([FromBody] CommentsDto entity) { var inputEntity = _mapper.Map <Comments>(entity); //if (await _commentService.IsExisted(entity.Name)) //{ // return new CustomApiResponse("CommentName đã tồn tại", true); //} var result = await _commentService.Add(inputEntity); return(new CustomApiResponse(result)); }
public bool Update(CommentsDto postdto) { try { var postmodel = mapper.Map <Comments>(postdto); CommentsRepository.Update(postmodel, postmodel); return(true); } catch (Exception) { return(false); } }
public bool Update(CommentsDto commentDto) { try { var comment = _mapper.Map <Comments>(commentDto); _commentsRepository.Update(comment); return(true); } catch (Exception) { return(false); } }
public async Task <IActionResult> GetComments(string app, DomainId commentsId, [FromQuery] long version = EtagVersion.Any) { var result = await commentsLoader.GetCommentsAsync(commentsId, version); var response = Deferred.Response(() => { return(CommentsDto.FromResult(result)); }); Response.Headers[HeaderNames.ETag] = result.Version.ToString(); return(Ok(response)); }
public bool Create(CommentsDto commentDto) { var comment = _mapper.Map <Comments>(commentDto); if (comment != null) { _commentsRepository.Add(comment); return(true); } else { return(false); } }
public async Task <IActionResult> AddComment([FromBody] CommentsDto newCommentDto) { var comment = _mapper.Map <Comments>(newCommentDto); comment.CreatedDate = DateTime.UtcNow; await _iCommentsRepository.Create(comment); if (await _iCommentsRepository.SaveAll()) { return(Ok(_mapper.Map <CommentsDto>(comment))); } throw new Exception("Error adding the category"); }
public bool Create(CommentsDto commentsDto) { var post = mapper.Map <Comments>(commentsDto); if (post != null) { CommentsRepository.Add(post); return(true); } else { return(false); } }
public static List <UserPostsDto> ConvertUserPostsToDTO(List <Posts> postsForUser) { var userPostsDto = new List <UserPostsDto>(); foreach (var post in postsForUser) { var userPostDto = new UserPostsDto() { Id = post.Id, PhotoUploaded = post.PhotoUploaded, TimeUploaded = post.TimeUploaded, Description = post.Description }; userPostDto.User.Id = post.User.Id; userPostDto.User.FullName = post.User.Name + ' ' + post.User.Surname; userPostDto.User.DateOfBirth = post.User.DateOfBirth; userPostDto.User.ProfilePicture = post.User.ProfilePicture; userPostDto.User.Gender = post.User.Gender; userPostDto.User.IsPrivate = post.User.IsPrivate; userPostDto.User.IsOnline = post.User.IsOnline; foreach (var like in post.Likes) { var newLikeDto = new LikesDto(); newLikeDto.DateCreated = like.DateCreated; newLikeDto.PostId = like.PostId; newLikeDto.User = ConvertSingleUserToDto(like.User); userPostDto.Likes.Add(newLikeDto); } foreach (var comment in post.Comments) { var newCommentDto = new CommentsDto(); newCommentDto.DateCreated = comment.DateCreated; newCommentDto.PostId = comment.PostId; newCommentDto.Comment = comment.Comment; newCommentDto.User = ConvertSingleUserToDto(comment.User); newCommentDto.Id = comment.Id; userPostDto.Comments.Add(newCommentDto); } userPostsDto.Add(userPostDto); } return(userPostsDto); }
public async Task <IActionResult> GetNotifications(DomainId userId, [FromQuery] long version = EtagVersion.Any) { CheckPermissions(userId); var result = await commentsLoader.GetCommentsAsync(userId, version); var response = Deferred.Response(() => { return(CommentsDto.FromResult(result)); }); Response.Headers[HeaderNames.ETag] = result.Version.ToString(); return(Ok(response)); }
public IActionResult PostComments([FromForm] CommentsDto comments) { try { var result = _commentsService.Create(comments); if (result) { return(RedirectToAction("GetPost")); } return(Ok(new { Message = "Error" })); } catch (DbUpdateConcurrencyException) { return(Ok(new { Message = "Error" })); } }
public void Execute(CommentsDto request) { _validator.ValidateAndThrow(request); var comment = new Comments { Subject = request.Subject, Text = request.Text, ArticleId = request.ArticleId, UserId = _actor.Id }; _context.Comments.Add(comment); _context.SaveChanges(); }
public async Task <ActionResult <CommentsDto> > Post(CommentsDto dto) { try { var mappedEntity = _mapper.Map <Comments>(dto); _eventRepository.Add(mappedEntity); if (await _eventRepository.Save()) { var location = _linkGenerator.GetPathByAction("Get", "Comments", new { mappedEntity.Id }); return(Created(location, _mapper.Map <CommentsDto>(mappedEntity))); } } catch (Exception ex) { return(this.StatusCode(StatusCodes.Status500InternalServerError, ex.InnerException.Message)); } return(BadRequest()); }
public async Task <IActionResult> AddComment(CommentsDto commentDto) { var newComment = await _repo.AddComment(commentDto); return(Ok(newComment)); }
public void Post([FromBody] CommentsDto dto, [FromServices] ICreateCommentCommand command) { executor.ExecuteCommand(command, dto); }
public async Task <ActionResult <Comments> > PostComments(int id, int articleId, CommentsDto comment) { //Create a new Comment var _comment = new Comments(); _comment.FK_UserID = id; _comment.FK_ArticleID = articleId; _comment.Note = comment.info; _context.Comments.Add(_comment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetComments", new { id = _comment.CommentID }, _comment)); }