Example #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);
                }
            }
        }
        private Comment GetCommentViaSqlReader(IDataReader readerSource)
        {
            var receivedComment = _commentBuilder.CreateComment(Convert.ToString(readerSource["CommentText"]),
                                                                Convert.ToDateTime(readerSource["CreationDate"]));
            var receivedCommentId = Convert.ToInt32(readerSource["CommentId"]);

            _commentBuilder.SetCommentId(receivedComment, receivedCommentId);

            return(receivedComment);
        }