コード例 #1
0
        public AnswerStatus CreateUser(BlogUserDto userDTO)
        {
            using (var uow = _unitOfWorkFactory.Create())
            {
                try
                {
                    var userToCreate   = _blogUserBuilder.CreateBlogUser(userDTO.UserName, userDTO.UserPassword);
                    var userRepository = _repositoryFactory.CreateUserRepository(uow);
                    int createdUserId  = userRepository.CreateEntity(userToCreate);

                    if (userDTO.UserBlog != null)
                    {
                        userDTO.Id = createdUserId;
                        userDTO.UserBlog.CreatedBy = userDTO;
                        var blogRepository = _repositoryFactory.CreateBlogRepository(uow);

                        var result = _blogService.CreateBlog(userDTO.UserBlog, blogRepository);

                        if (result == AnswerStatus.Failed)
                        {
                            return(AnswerStatus.Failed);
                        }
                    }

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

                    return(AnswerStatus.Failed);
                }
            }
        }
コード例 #2
0
        public AnswerStatus CreateBlog(BlogDto blogDTO)
        {
            try
            {
                using (var uow = _unitOfWorkFactory.Create())
                {
                    var blogRepository = _repositoryFactory.CreateBlogRepository(uow);

                    var result = CreateBlog(blogDTO, blogRepository);

                    if (result == AnswerStatus.Failed)
                    {
                        return(result);
                    }

                    uow.SaveChanges();
                    return(result);
                }
            }
            catch (Exception exc)
            {
                _logger.Log(exc.ToString());

                return(AnswerStatus.Failed);
            }
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
        public AnswerStatus CreatePost(PostDto postDTO)
        {
            using (var uow = _unitOfWorkFactory.Create())
            {
                try
                {
                    var postToCreate   = _postBuilder.CreatePost(postDTO.PostTitle, postDTO.PostContent, postDTO.CreationDate);
                    var blogRepository = _repositoryFactory.CreateBlogRepository(uow);
                    var postBlog       = blogRepository.GetEntityById(postDTO.RelatedTo.Id);
                    _postBuilder.SetBlogRelatedTo(postToCreate, postBlog);

                    var postRepository = _repositoryFactory.CreatePostRepository(uow);
                    postRepository.CreateEntity(postToCreate);

                    var categoryRepository = _repositoryFactory.CreateCategoryRepository(uow);
                    if (postDTO.PostCategories != null)
                    {
                        foreach (var categoryDTO in postDTO.PostCategories)
                        {
                            var categoryToAdd = categoryRepository.GetEntityById(categoryDTO.Id);
                            if (categoryToAdd != null)
                            {
                                postRepository.AddCategoryToPost(postToCreate, categoryToAdd);
                            }
                        }
                    }

                    uow.SaveChanges();

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

                    return(AnswerStatus.Failed);
                }
            }
        }