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); }
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(); } }
public override IList <Category> GetAllCategoriesBelow(string id) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { CategoryDataStore dataStore = new CategoryDataStore(transaction); return(dataStore.FindByChildOfCategory(id)); } }