コード例 #1
0
        public override Article CreateArticle(Category category, string owner,
                                              string name, string fileName, string title,
                                              string description, string body, bool isUpload, bool isEnabled, bool isNumbChaps,
                                              bool isAckRequired)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ArticleDataStore articleStore = new ArticleDataStore(transaction);
                if (articleStore.FindByName(name) != null)
                {
                    throw new ArticleNameAlreadyExistsException(name);
                }

                CategoryDataStore dataStore = new CategoryDataStore(transaction);
                dataStore.Attach(category);

                Article article = new Article(category, name, fileName, owner, title, description, body, isUpload, isEnabled, isNumbChaps);
                article.Author = owner;
                //article.Tag = isAckRequired.ToString();
                article.RequiresAck = isAckRequired;

                if (category.AutoApprove)
                {
                    article.Approved = true;
                }

                articleStore.Insert(article);
                transaction.Commit();

                return(article);
            }
        }
コード例 #2
0
        public override IList <Article> GetArticles(Category category, ArticleStatus status, bool recursive)
        {
            IList <Article> articles = null;

            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ArticleDataStore dataStore = new ArticleDataStore(transaction);
                articles = dataStore.FindByCategoryAndOwner(category, null, status);
                if (recursive)
                {
                    // Find children of this parent category.
                    CategoryDataStore ds = new CategoryDataStore(transaction);
                    IList <Category>  childCategories = ds.FindByChildOfCategory(category.Id);
                    foreach (Category subCategory in childCategories)
                    {
                        IList <Article> subArticles = dataStore.FindByCategoryAndOwner(subCategory, null, status);
                        foreach (Article subArticle in subArticles)
                        {
                            articles.Add(subArticle);
                        }
                    }
                }
            }
            return(articles);
        }
コード例 #3
0
        public override void DeleteCategory(Category category)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore = new CategoryDataStore(transaction);

                // Delete should only be allowed if the following conditions are true:
                // 1. There are no child categories.
                if (dataStore.FindByChildOfCategory(category.Id).Count > 0)
                {
                    throw new SchemaIntegrityException("Category has child categories");
                }

                // 2. There are no articles associated with this category.
                ArticleDataStore ads = new ArticleDataStore(transaction);
                if (ads.FindByCategory(category).Count > 0)
                {
                    throw new SchemaIntegrityException("Articles are associated with this category");
                }

                // Delete all access items.
                AccessLayer.AccessDataStore accessDs  = new AccessLayer.AccessDataStore(transaction);
                IList <AccessLayer.Access>  allAccess = accessDs.FindAllByItem(category.Id);

                foreach (AccessLayer.Access access in allAccess)
                {
                    access.Deleted = true;
                    accessDs.Update(access);
                }

                category.Deleted = true;
                dataStore.Update(category);
                transaction.Commit();
            }
        }
コード例 #4
0
 public override IList <Category> GetAllCategoriesBelow(string id)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         CategoryDataStore dataStore = new CategoryDataStore(transaction);
         return(dataStore.FindByChildOfCategory(id));
     }
 }
コード例 #5
0
 public override IList <Category> GetAllCategories()
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         CategoryDataStore dataStore = new CategoryDataStore(transaction);
         return(dataStore.FindAll());
     }
 }
コード例 #6
0
        public override IList <Category> GetCategoryByLikeName(string name, bool throwIfNotFound)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore  = new CategoryDataStore(transaction);
                IList <Category>  categories = dataStore.FindByLikeName(name);

                return(categories);
            }
        }
コード例 #7
0
        public override Category GetCategoryByName(string name, bool throwIfNotFound)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore = new CategoryDataStore(transaction);
                Category          category  = dataStore.FindByName(name);

                return(category);
            }
        }
コード例 #8
0
        public override void UpdateCategory(Category category)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore = new CategoryDataStore(transaction);

                dataStore.Update(category);

                transaction.Commit();
            }
        }
コード例 #9
0
        public override Category CreateCategory(string displayName)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore = new CategoryDataStore(transaction);

                Category category = new Category(displayName);

                dataStore.Insert(category);

                transaction.Commit();

                return(category);
            }
        }
コード例 #10
0
        public override Category GetCategory(string id)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                CategoryDataStore dataStore = new CategoryDataStore(transaction);

                Category category = dataStore.FindByKey(id);
                if (category == null)
                {
                    throw new DocoCategoryNotFoundException(id);
                }

                return(category);
            }
        }