コード例 #1
0
        public async Task AddCommentAsync(CommentPostDto comment)
        {
            var newComment = _mapper.Map <Comment>(comment);

            await _appContext.Comments.AddAsync(newComment);

            await _appContext.SaveChangesAsync(default);
コード例 #2
0
        public Comment Create(CommentPostDto commentDto)
        {
            Comment toAdd = CommentPostDto.ToComment(commentDto);

            context.Comments.Add(toAdd);
            context.SaveChanges();
            return(toAdd);
        }
コード例 #3
0
        public async Task <ActionResult> Create([FromBody] CommentPostDto comment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Model state is not valid"));
            }

            await _commentManager.AddCommentAsync(comment);

            return(Ok());
        }
コード例 #4
0
        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)));
        }
コード例 #5
0
        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 }));
        }
コード例 #6
0
        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));
        }
コード例 #7
0
ファイル: CommentDtoMapper.cs プロジェクト: esraa-96/Facebook
        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);
        }
コード例 #8
0
        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));
        }
コード例 #9
0
        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)));
        }
コード例 #10
0
 public async Task AddComment(CommentPostDto insertDto)
 {
     await _commentRepository.InsertOneAsync(_mapper.Map <CommentPostDto, Comment>(insertDto));
 }
コード例 #11
0
 public async Task AddAsync(CommentPostDto commentPostDto)
 {
     await _mongoRepository.InsertOneAsync(_mapper.Map <CommentPostDto, Comment>(commentPostDto));
 }
コード例 #12
0
        public async Task <ActionResult> AddComment(CommentPostDto comment)
        {
            await _commentService.AddComment(comment);

            return(Created("AddComment", comment));
        }
コード例 #13
0
        public async Task <IActionResult> Add(CommentPostDto commentPostDto)
        {
            await _commentService.AddAsync(commentPostDto);

            return(Created("Add", commentPostDto));
        }