Ejemplo n.º 1
0
        public AnswerStatus CreateComment(CommentDto commentDTO)
        {
            using (var uow = _unitOfWorkFactory.Create())
            {
                try
                {
                    var postRepository = _repositoryFactory.CreatePostRepository(uow);
                    var userRepository = _repositoryFactory.CreateUserRepository(uow);

                    var commentToCreate = _commentBuilder.CreateComment(commentDTO.CommentText, commentDTO.CreationDate);
                    var postRelatedTo   = postRepository.GetEntityById(commentDTO.RelatedTo.Id);
                    _commentBuilder.SetPostRelatedTo(commentToCreate, postRelatedTo);
                    var userCreatedBy = userRepository.GetEntityById(commentDTO.CreatedBy.Id);
                    _commentBuilder.SetUserCreatedBy(commentToCreate, userCreatedBy);

                    var commentRepository = _repositoryFactory.CreateCommentRepository(uow);
                    commentRepository.CreateEntity(commentToCreate);

                    uow.SaveChanges();

                    return(AnswerStatus.Successfull);
                }
                catch (Exception exc)
                {
                    _logger.Log(exc.ToString());

                    return(AnswerStatus.Failed);
                }
            }
        }
Ejemplo n.º 2
0
        private AnswerStatus RemoveUserComments(int userId, IUnitOfWork uow)
        {
            var commentRepository = _repositoryFactory.CreateCommentRepository(uow);
            var userComments      = commentRepository.GetUserComments(userId);

            if (userComments != null)
            {
                foreach (var comment in userComments)
                {
                    commentRepository.DeleteEntity(comment);
                }
            }


            return(AnswerStatus.Successfull);
        }
Ejemplo n.º 3
0
        private AnswerStatus DeletePostComments(int postId, IUnitOfWork uow)
        {
            var commentRepository = _repositoryFactory.CreateCommentRepository(uow);

            var postComments = commentRepository.GetPostComments(postId);

            if (postComments != null)
            {
                foreach (var comment in postComments)
                {
                    commentRepository.DeleteEntity(comment);
                }
            }

            return(AnswerStatus.Successfull);
        }