Esempio n. 1
0
        private Blog GetBlogViaSqlReader(IDataReader readerSource)
        {
            readerSource.Read();

            var receivedBlog = _blogBuilder.CreateBlog(Convert.ToString(readerSource["BlogTitle"]),
                                                       Convert.ToDateTime(readerSource["CreationDate"]));
            var receivedBlogId = Convert.ToInt32(readerSource["BlogId"]);

            _blogBuilder.SetBlogId(receivedBlog, receivedBlogId);
            readerSource.Close();
            var userRelatedWithBlog = _blogUserRepository.GetBlogUserByBlogId(receivedBlogId);

            _blogUserBuilder.SetUserBlog(userRelatedWithBlog, receivedBlog);
            _blogBuilder.SetBlogUser(receivedBlog, userRelatedWithBlog);

            var receivedBlogCategories = _categoryRepository.GetBlogCategories(receivedBlogId);

            foreach (var categoryToAdd in receivedBlogCategories)
            {
                _categoryBuilder.SetBlogRelatedTo(categoryToAdd, receivedBlog);
                receivedBlog.AddCategory(categoryToAdd);
            }

            var receivedBlogPosts = _postRepository.GetPostsByBlogId(receivedBlogId);

            foreach (var postToAdd in receivedBlogPosts)
            {
                _postBuilder.SetBlogRelatedTo(postToAdd, receivedBlog);
                receivedBlog.AddPost(postToAdd);
            }

            return(receivedBlog);
        }
        public AnswerStatus CreateCategory(CategoryDto categoryDTO, ICategoryRepository categoryRepository)
        {
            try
            {
                var blogRepository   = _repositoryFactory.CreateBlogRepository(categoryRepository.UnitOfWork);
                var categoryToCreate = _categoryBuilder.CreateCategory(categoryDTO.CategoryName);
                var categoryBlog     = blogRepository.GetEntityById(categoryDTO.RelatedTo.Id);
                _blogBuilder.SetBlogId(categoryBlog, categoryDTO.RelatedTo.Id);
                _categoryBuilder.SetBlogRelatedTo(categoryToCreate, categoryBlog);

                categoryRepository.CreateEntity(categoryToCreate);

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

                return(AnswerStatus.Failed);
            }
        }