public CommentConfirmationDto Create(CommentCreateDto dto)
        {
            User user = MockedData.Users.FirstOrDefault(e => e.Id == dto.UserId);

            if (user == null)
            {
                throw new BusinessException("User does not exit");
            }

            Post post = MockedData.Posts.FirstOrDefault(e => e.Id == dto.UserId);

            if (post == null)
            {
                throw new BusinessException("Post does not exit");
            }

            Comment comment = new Comment()
            {
                Id        = Guid.NewGuid(),
                Content   = dto.Content,
                CreatedAt = DateTime.UtcNow,
                UserId    = dto.UserId,
                PosId     = dto.PosId
            };

            _context.Comments.Add(comment);
            _context.SaveChanges();

            _logger.Log("Comment created");

            return(_mapper.Map <CommentConfirmationDto>(comment));
        }
Exemplo n.º 2
0
        public async Task <List <CommentDto> > AddCommentToPostAsync(CommentCreateDto commentDto)
        {
            var comment     = _mapper.Map <CommentCreateDto, Comment>(commentDto);
            var queryResult = await _postRepository.FindByIdFirstAsync(commentDto.PostId);

            var postResult = queryResult;

            if (postResult == null)
            {
                throw new ResourceNotFoundException("Post not found");
            }

            if (postResult.Comments == null)
            {
                postResult.Comments = new List <Comment>();
            }

            comment.SetModificationAndCreationTime();
            postResult.Comments.Add(comment);
            postResult.SetModificationTime();
            _postRepository.Save();

            var comments = postResult.Comments;

            var commentsDto = new List <CommentDto>();

            foreach (var c in comments)
            {
                commentsDto.Add(_mapper.Map <Comment, CommentDto>(c));
            }

            return(commentsDto);
        }
        public CommentConfirmationDto Update(Guid id, CommentCreateDto dto)
        {
            var comment = _context.Comments.FirstOrDefault(e => e.Id == id);

            if (comment == null)
            {
                throw new BusinessException("Comment with provided id does not exist");
            }

            User user = MockedData.Users.FirstOrDefault(e => e.Id == dto.UserId);

            if (user == null)
            {
                throw new BusinessException("User does not exit");
            }

            Post post = MockedData.Posts.FirstOrDefault(e => e.Id == dto.UserId);

            if (post == null)
            {
                throw new BusinessException("Post does not exit");
            }

            comment.Content = dto.Content;
            comment.UserId  = dto.UserId;
            comment.PosId   = dto.PosId;

            _context.SaveChanges();

            _logger.Log("Comment updated");

            return(_mapper.Map <CommentConfirmationDto>(comment));
        }
Exemplo n.º 4
0
        CommentGetDto ICommentBusinessLogic.Create(CommentCreateDto comment)
        {
            Comment newComment = mapper.Map <Comment>(comment);

            newComment.ApprovedImage = false;
            newComment.ApprovedText  = false;
            commentRepository.Insert(newComment);

            Post post = postRepository.GetById(comment.PostId);

            ++post.CommentsCount;
            postRepository.Update(post);
            postRepository.SaveChanges();

            CreateContentScanTaskDto createContentScanTaskDto = new CreateContentScanTaskDto()
            {
                ImageUrl    = null,
                Text        = newComment.Text,
                CallbackUrl = $"/api/v1/trends/{post.TrendId}/posts/{post.Id}/comments/{newComment.Id}/content-scan-result"
            };

            contentScanTaskService.CreateTask(createContentScanTaskDto);

            return(mapper.Map <CommentGetDto>(newComment));
        }
Exemplo n.º 5
0
        public async Task <CommentDto> CreateAsync(CommentCreateDto dto)
        {
            var user = await _context.Users.FindAsync(dto.UserId);

            var post = await _context.Posts.FindAsync(dto.PostId);

            if (user == null || post == null)
            {
                return(null);
            }

            var comment = new Comment()
            {
                Body   = dto.Content,
                Type   = dto.Type,
                PostId = dto.PostId,
                UserId = user.Id
            };

            _context.Comments.Add(comment);

            await _context.SaveChangesAsync();

            return(comment.ToDto());
        }
Exemplo n.º 6
0
        // POST /api/comments
        public async Task <IActionResult> Create([FromBody] CommentCreateDto dto)
        {
            var userId = User.GetUserId();
            var user   = await _repo.GetUser(userId);

            //var issue = await _repo.GetIssue(dto.IssueId);

            var comment = new Comment
            {
                Text        = dto.Text,
                CreatedAt   = DateTime.Now,
                CreatedById = userId,
                IssueId     = dto.IssueId,
                CreatedBy   = user
            };

            _repo.Add(comment);

            if (await _repo.SaveAll())
            {
                var commentToReturn = _mapper.Map <CommentDto>(comment);
                return(Ok(commentToReturn));
            }

            return(BadRequest());
        }
Exemplo n.º 7
0
        public async Task <IActionResult> PostCommentOnMovie(string movieId, [FromBody] CommentCreateDto dto)
        {
            var userId = User.GetUserId();

            if (userId == null)
            {
                return(BadRequest(new { message = "User is not authenticated" }));
            }

            if (movieId == null)
            {
                return(NotFound(new { message = "Movie not found" }));
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var comment = _mapper.Map <CommentCreateDto, Comment>(dto);

            comment.MovieId = movieId;
            comment.UserId  = userId;

            await _service.CreateComment(comment);

            return(Ok(new { message = "Comment successfully posted" }));
        }
Exemplo n.º 8
0
        public IHttpActionResult CreateComment(int pushId, string content)
        {
            var anunt = _anuntService.GetAnuntWithRole(pushId);

            if (User.IsInRole(anunt.Role))
            {
                var dto = new CommentCreateDto()
                {
                    Content = content,
                    Author  = User.Identity.GetUserName(),
                    Created = DateTime.Now,
                    PushId  = pushId
                };

                _commentsService.CreateComment(dto);

                var commentItem = new CommentItemDto()
                {
                    Author  = dto.Author,
                    Content = dto.Content,
                    Created = dto.Created
                };

                _signalRHelper.NotifyCommentsForPush(commentItem, pushId);

                return(Ok());
            }

            return(BadRequest());
        }
Exemplo n.º 9
0
 public static Comment ToEntity(CommentCreateDto dto)
 {
     return(new Comment
     {
         Content = dto.Content
     });
 }
Exemplo n.º 10
0
        public async void CreateCommentForApplicationShouldCreateAnewComment()
        {
            var applicationToTest = await _fixture.GetHttpResult(UrlPath + _applicationId);

            var currentNumberOfComments =
                JsonConvert.DeserializeObject <ApplicationDetailDto>(applicationToTest.Content.ReadAsStringAsync().Result)
                .Comments.Count();

            var newComment = new CommentCreateDto()
            {
                IsPrivate       = false,
                RequiresChanges = true,
                Message         = "Test Kommentar",
                // TODO Look at that again!!!
                UserId =
                    JsonConvert.DeserializeObject <ApplicationDetailDto>(applicationToTest.Content.ReadAsStringAsync().Result)
                    .User.Id
            };

            var serializedComment = JsonConvert.SerializeObject(newComment);
            var result            = await _fixture.PostHttpResult(UrlPath + _applicationId + "/comments/", serializedComment);

            result.Should().NotBeNull();
            result.StatusCode.Should().Be(HttpStatusCode.Created);

            applicationToTest = await _fixture.GetHttpResult(UrlPath + _applicationId);

            var newNumberOfComments = JsonConvert.DeserializeObject <ApplicationDetailDto>(applicationToTest.Content.ReadAsStringAsync().Result)
                                      .Comments.Count();

            newNumberOfComments.Should().Be(currentNumberOfComments + 1);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> ImagePut(
            [FromBody] CommentCreateDto model
            )
        {
            await _commentService.Create(model);

            return(NoContent());
        }
Exemplo n.º 12
0
 public async Task CommentPost(CommentCreateDto dto)
 {
     ValidateModelOrThrow();
     var command = new CommentCreateCommand()
     {
         Input = dto
     };
     await CommandBus.SendAsync(command);
 }
Exemplo n.º 13
0
 private static Comment Map(CommentCreateDto dto) =>
     new Comment
     {
         Id = dto.Id,
         ActivityId = dto.ActivityId,
         UserId = dto.UserId,
         Text = dto.Text,
         ParentId = dto.ParentId
     };
Exemplo n.º 14
0
        public async Task <ActionResult <CommentDto> > PostComment(long id, [FromBody] CommentCreateDto dto)
        {
            var commentDto = _commentRepository.CreateAsync(dto);

            if (commentDto == null)
            {
                return(BadRequest());
            }
            return(Ok(commentDto));
        }
Exemplo n.º 15
0
        public async Task <IActionResult> Add(CommentCreateDto commentCreateDto)
        {
            var result = await _commentService.Add(commentCreateDto);

            if (result.Success)
            {
                return(Ok(result.Message));
            }
            return(BadRequest(result.Message));
        }
Exemplo n.º 16
0
        public ActionResult <CommentReadDto> CreateComment(CommentCreateDto _CommentCreateDto)
        {
            var commentModel = _mapper.Map <Comment>(_CommentCreateDto);

            _repository.createComment(commentModel);
            _repository.SaveChanges();
            var commentItem = _mapper.Map <CommentReadDto>(commentModel);

            return(Ok(commentItem));
        }
Exemplo n.º 17
0
        [HttpPost("add")]//+++
        public IActionResult Add(CommentCreateDto commentCreateDto)
        {
            var result = _commentservice.Add(commentCreateDto);

            if (result.Success)
            {
                return(Ok(result.Message));
            }

            return(BadRequest(result.Message));
        }
Exemplo n.º 18
0
        public CommentReadDto CreateComment(CommentCreateDto commentDto, int postId, int userId)
        {
            var post          = _postsRepository.FindById(postId);
            var commentEntity = Converter.ToEntity(commentDto);

            commentEntity.UserId = userId;
            commentEntity.Date   = DateTime.Now;
            post.Comments.Add(commentEntity);
            _postsRepository.Persist();
            return(Converter.ToDto(commentEntity));
        }
Exemplo n.º 19
0
 public virtual CommentModel Create(CommentCreateDto dto)
 {
     var entity = Map(dto);
     entity.CreatedDate = entity.ModifyDate = DateTime.UtcNow;
     _commentsRepository.Add(entity);
     if (dto.LinkPreviewId.HasValue)
     {
         _commentLinkPreviewService.AddLinkPreview(entity.Id, dto.LinkPreviewId.Value);
     }
     return entity.Map<CommentModel>();
 }
Exemplo n.º 20
0
        public ActionResult <CommentReadDto> CreateComment(int id, CommentCreateDto com)
        {//Needs Authentication
            var comModel = _mapper.Map <Comment>(com);

            _repository.Add(comModel);
            _repository.Save();

            var readDto = _mapper.Map <CommentReadDto>(comModel);

            return(CreatedAtRoute(nameof(GetCommentById), new { id = comModel.ID }, readDto));
        }
Exemplo n.º 21
0
 public virtual async Task<CommentModel> CreateAsync(CommentCreateDto dto)
 {
     var entity = Map(dto);
     entity.CreatedDate = entity.ModifyDate = DateTime.UtcNow;
     await _commentsRepository.AddAsync(entity);
     if (dto.LinkPreviewId.HasValue)
     {
         await _commentLinkPreviewService.AddLinkPreviewAsync(entity.Id, dto.LinkPreviewId.Value);
     }
     return entity.Map<CommentModel>();
 }
Exemplo n.º 22
0
 public static Comment ToModel(this CommentCreateDto response)
 {
     return(new Comment()
     {
         Id = Guid.NewGuid(),
         Created = DateTime.UtcNow,
         IsPrivate = response.IsPrivate,
         RequiresChanges = response.RequiresChanges,
         Message = response.Message,
         UserId = response.UserId
     });
 }
Exemplo n.º 23
0
        // adds a comment to an specific application and returns the comment as a DTO
        public CommentDto AddCommentToApplication(Guid applicationId, CommentCreateDto comment)
        {
            var newComment = comment.ToModel();

            newComment.ApplicationId = applicationId;

            _applicationDbContext.Comment.Add(newComment);
            Save();
            return(_applicationDbContext.Comment.Include(dto => dto.User)
                   .SingleOrDefault(dto => dto.Id == newComment.Id)
                   .ToDto());
        }
Exemplo n.º 24
0
        public async Task <long> CreateComment(CommentCreateDto commentCreate)
        {
            var user = await _userRepository.GetById(commentCreate.UserId, u => u.Reviewer);

            commentCreate.ReviewerId = user.Reviewer.Id;

            var comment = _mapper.Map <Comment>(commentCreate);

            await _repository.Insert(comment);

            return(comment.Id);
        }
Exemplo n.º 25
0
        public ActionResult <CommentReadDto> CreateComment(CommentCreateDto commentCreateDto)
        {
            var commentModel = _mapper.Map <Comment>(commentCreateDto);

            _repository.CreateComment(commentModel);
            _repository.SaveChanges();

            var commentReadDto = _mapper.Map <CommentReadDto>(commentModel);

            return(CreatedAtRoute(nameof(GetCommentById),
                                  new { ID = commentReadDto.ID }, commentReadDto));
        }
Exemplo n.º 26
0
        public IActionResult Create([FromBody] CommentCreateDto data)
        {
            if (string.IsNullOrEmpty(data.Content))
            {
                return(BadRequest());
            }

            var userId = ClaimsReader.GetUserId(Request);
            var post   = context.Posts.FirstOrDefault(a => a.Id == data.PostId);

            if (post == null)
            {
                return(NotFound());
            }

            if (!context.UserGroups.Any(a => a.GroupId == post.GroupId && a.UserId == userId && (a.Relation == GroupRelation.Owner || a.Relation == GroupRelation.User)))
            {
                return(BadRequest());
            }

            var comment = new Comment
            {
                DateAdded = DateTime.UtcNow,
                Content   = data.Content,
                PostId    = data.PostId,
                UserId    = userId
            };

            context.Comments.Add(comment);

            try
            {
                context.SaveChanges();

                var user = context.Users.FirstOrDefault(a => a.Id == userId);

                var result = new CommentDto
                {
                    Id        = comment.Id,
                    Content   = comment.Content,
                    DateAdded = comment.DateAdded,
                    Owner     = user.Login,
                    IsOwner   = true
                };

                return(Ok(result));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }
Exemplo n.º 27
0
        // updates a specific comment of an application
        public CommentDto UpdateCommentOfApplication(Guid applicationId, Guid commentId,
                                                     CommentCreateDto modifiedComment)
        {
            var commentToEdit = _applicationDbContext.Comment.Include(comment => comment.User)
                                .SingleOrDefault(comment => comment.Id == commentId);

            commentToEdit.RequiresChanges = modifiedComment.RequiresChanges;
            commentToEdit.IsPrivate       = modifiedComment.IsPrivate;
            commentToEdit.Message         = modifiedComment.Message;
            commentToEdit.UserId          = modifiedComment.UserId;

            return(commentToEdit.ToDto());
        }
Exemplo n.º 28
0
        protected virtual CommentCreateDto MapToCreateDto(CommentCreateModel createModel, Guid activityId)
        {
            var currentMemberId = _intranetMemberService.GetCurrentMember().Id;
            var dto             = new CommentCreateDto(
                Guid.NewGuid(),
                currentMemberId,
                activityId,
                createModel.Text,
                createModel.ParentId,
                createModel.LinkPreviewId);

            return(dto);
        }
Exemplo n.º 29
0
        public async Task <IResult> Add(CommentCreateDto commentCreateDto)
        {
            var comment = new Comment
            {
                Content   = commentCreateDto.Content,
                UserId    = commentCreateDto.UserId,
                ProductId = commentCreateDto.ProductId,
                Created   = DateTime.Now
            };
            await _commentDal.Add(comment);

            return(new SuccessResult(Messages.CommentAdded));
        }
Exemplo n.º 30
0
        public void CreateComment(CommentCreateDto dto)
        {
            var comment = new Comment()
            {
                AnuntId = dto.PushId,
                Author  = dto.Author,
                Content = dto.Content,
                Created = dto.Created
            };

            _commentsRepo.Insert(comment);
            _commentsRepo.Save();
        }