예제 #1
0
        public void AddComment(Comment comment)
        {
            _logger.LogInformation("Call AddComment method");

            _validator.ValidateComment(comment);
            _repository.CreateComment(comment);
        }
        public async Task CreateComment_Valid_Success()
        {
            // Arrange
            var comment = _stubComment;

            // Act
            var success = await _commentsRepository.CreateComment(comment);

            // Assert
            Assert.IsNotNull(success);
            Assert.IsTrue(success);
        }
예제 #3
0
        Comment ICommentsService.CreateComment(Comment comment)
        {
            // Validate the stars quantity (range 1-5)
            if (comment.Stars < 1 || comment.Stars > 5)
            {
                throw new AlreadyExistsException("The valid star range is between 1 and 5");
            }
            // Validating that it's the only comment for the idea
            var newComment = _commentsRepository.GetCommentGivenAnUserAndAnIdea(comment.GivenBy, comment.GivenTo);

            if (newComment != null)
            {
                throw new AlreadyExistsException("This user has already commented on this idea");
            }

            // Validating that Comment is posted to ideas of a different user.
            var idea = _ideasRepository.GetIdeaById(comment.GivenTo);

            if (idea != null)
            {
                if (comment.GivenBy == idea.ProposedBy)
                {
                    throw new AlreadyExistsException("Comment can only be posted to ideas that were not created by the same user");
                }
            }

            // Increasing +1 the number of Comments in Ideas
            if (idea != null)
            {
                if (!_ideasRepository.IncreaseNumberOfComments(idea.Id))
                {
                    throw new NotFoundException("Cannot find idea");
                }
            }

            // Update the average of stars ----------------------------------------------------------------
            if (idea != null)
            {
                long newAverageOfStars = _commentsRepository.GetNewAverageRegardingTheCurrentComment(idea.Id, comment.Stars);
                if (!_ideasRepository.UpdateAverageStars(idea.Id, newAverageOfStars))
                {
                    throw new NotFoundException("Cannot find idea");
                }
            }
            // --------------------------------------------------------------------------------------------

            newComment = _commentsRepository.CreateComment(comment);
            return(newComment);
        }
예제 #4
0
 public async Task <IActionResult> CreateComment(Comment _input)
 {
     if (ModelState.IsValid)
     {
         return(Ok(await Task.Run(() => repository.CreateComment(_input))));
     }
     else
     {
         Dictionary <string, object> data = new Dictionary <string, object>();
         data.Add("Response", "Error");
         data.Add("Code", "FCE00006");
         data.Add("Description", "Invalid JSON");
         data.Add("Data", null);
         return(Ok(data));
     }
 }
        public async Task <ActionResult> CreateComment([FromBody] Comment comment)
        {
            try
            {
                if (comment == null)
                {
                    return(BadRequest());
                }

                await commentsRepository.CreateComment(comment);

                return(Ok());
            }
            catch (Exception)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError,
                                  "Error creating new mem record"));
            }
        }
예제 #6
0
        public ActionResult CreateComment(Comment comment)
        {
            if (UsersHelper.LoggedInUserUsername(Session) == null)
            {
                return(null);
            }
            var currentUser = UsersHelper.LoggedInUserUsername(Session);

            if (currentUser == null)
            {
                return(null);
            }
            comment.CommentOwner = currentUser;
            comment.DatePosted   = DateTime.Now;
            _commentsRepository.CreateComment(comment);

            ViewBag.Values = Comment.CommentsSortOrderSelectList();
            var cdto = CommentDTO.ConvertCommentToDTO(comment);

            return(PartialView("SingleComment", cdto));
        }
        public async Task <IActionResult> CreateComment([FromBody] CommentDto comment)
        {
            var success = await _commentsRepository.CreateComment(comment);

            return(Ok(success));
        }
예제 #8
0
 public Task CreateComment(Comment comment)
 {
     return(_commentsRepository.CreateComment(comment));
 }
예제 #9
0
 public async Task <int> CreateComment(CreateCommentVm model)
 {
     return(await _commentsRepository.CreateComment(_mapper.Map <CreateCommentDto>(model)));
 }