public async Task AddCommentAsync(CommentPostDto comment) { var newComment = _mapper.Map <Comment>(comment); await _appContext.Comments.AddAsync(newComment); await _appContext.SaveChangesAsync(default);
public Comment Create(CommentPostDto commentDto) { Comment toAdd = CommentPostDto.ToComment(commentDto); context.Comments.Add(toAdd); context.SaveChanges(); return(toAdd); }
public async Task <ActionResult> Create([FromBody] CommentPostDto comment) { if (!ModelState.IsValid) { return(BadRequest("Model state is not valid")); } await _commentManager.AddCommentAsync(comment); return(Ok()); }
public async Task <Comment> AddAsync(CommentPostDto entity) { CommentPostDtoValidator validator = new CommentPostDtoValidator(); ValidationResult results = validator.Validate(entity); if (!results.IsValid) { throw new ValidationException("CommentPostDTO", string.Join(". ", results.Errors)); } return(await _repository.AddAsync(mapper.Map <Comment>(entity))); }
public IActionResult AddComment([FromBody] CommentPostDto commentPostDto) { if (commentPostDto == null || commentPostDto.CommentContent == null) { return(Json(new { statusCode = ResponseStatus.ValidationError, responseMessage = ValidationMessages.EmptyComment })); } User user = userData.GetUser(HttpContext); Comment comment = CommentDtoMapper.Map(commentPostDto, user.Id); facebookDataContext.Comments.Add(comment); try { facebookDataContext.SaveChanges(); } catch { return(Json(new { statusCode = ResponseStatus.Error })); } comment = facebookDataContext.Comments.Where(x => x.Id == comment.Id).Include("User.ProfilePhotos").FirstOrDefault(); return(Json(new { statusCode = ResponseStatus.Success, responseMessage = HomePageDtoMapper.Map(comment, hostingEnvironment, user.Id), postId = comment.PostId })); }
public async Task <IActionResult> PostComment(CommentPostDto commentPostDto) { DateTime timeStamp = DateTime.Now; var mappedComment = _mapper.Map <Comment> (commentPostDto); mappedComment.Username = User.FindFirst(ClaimTypes.Name).Value; mappedComment.UserId = int.Parse(User.FindFirst(ClaimTypes.NameIdentifier).Value); mappedComment.TimeStamp = timeStamp; await _context.Comments.AddAsync(mappedComment); await _context.SaveChangesAsync(); await _hubContext.Clients.Group(mappedComment.ThreadId.ToString()).SendAsync("newComment", mappedComment); return(StatusCode(201)); }
public static Comment Map(CommentPostDto from, int userId) { if (from == null) { return(null); } var to = new Comment { CommentContent = from.CommentContent, IsDeleted = false, PostId = from.PostId, CreatedAt = DateTime.Now, UserId = userId }; return(to); }
public async Task <ActionResult <CommentGetDto> > Create([FromBody] CommentPostDto commentDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userId = ApplicationUserConfiguration.SupervisorIdTmp; var comment = _mapper.Map <Comment>(commentDto); comment.CreationTime = DateTime.Now; comment.SupervisorId = userId; await _unitOfWork.Comments.Add(comment); await _unitOfWork.Complete(); var commentGetDto = _mapper.Map <CommentGetDto>(comment); return(Ok(commentGetDto)); }
public async Task <IActionResult> AddNewComment([FromBody] CommentPostDto commentPostDto) { var commentResp = await commentService.AddAsync(commentPostDto); return(CreatedAtAction("GetClient", new { id = commentResp.ID }, mapper.Map <CommentResponseDto>(commentResp))); }
public async Task AddComment(CommentPostDto insertDto) { await _commentRepository.InsertOneAsync(_mapper.Map <CommentPostDto, Comment>(insertDto)); }
public async Task AddAsync(CommentPostDto commentPostDto) { await _mongoRepository.InsertOneAsync(_mapper.Map <CommentPostDto, Comment>(commentPostDto)); }
public async Task <ActionResult> AddComment(CommentPostDto comment) { await _commentService.AddComment(comment); return(Created("AddComment", comment)); }
public async Task <IActionResult> Add(CommentPostDto commentPostDto) { await _commentService.AddAsync(commentPostDto); return(Created("Add", commentPostDto)); }