public override IList <Category> GetCategories(string rootCategoryId, bool recursive) { List <Category> categories = new List <Category>(); IList <Category> children = new List <Category>(); using (TransactionScope transaction = new TransactionScope(mConfiguration)) { CategoryDataStore dataStore = new CategoryDataStore(transaction); Category category = dataStore.FindByKey(rootCategoryId); if (category == null) { throw new NewsCategoryNotFoundException(rootCategoryId); } categories.Add(category); if (recursive) { // Find child categories. children = dataStore.FindAllChildren(rootCategoryId); } } foreach (Category childCategory in children) { categories.AddRange(GetCategories(childCategory.Id, recursive)); } return(categories); }
public override IList <Category> GetAllCategories() { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { CategoryDataStore dataStore = new CategoryDataStore(transaction); return(dataStore.FindAll()); } }
public override IList <Category> GetCategoryByLikeName(string name, bool throwIfNotFound) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { CategoryDataStore dataStore = new CategoryDataStore(transaction); return(dataStore.FindByLikeName(name)); } }
public override void UpdateCategory(Category category) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { CategoryDataStore dataStore = new CategoryDataStore(transaction); dataStore.Update(category); transaction.Commit(); } }
public override Category CreateCategory(string name) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { CategoryDataStore dataStore = new CategoryDataStore(transaction); Category category = new Category(name); dataStore.Insert(category); transaction.Commit(); return(category); } }
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 NewsCategoryNotFoundException(id); } return(category); } }
public override Category GetCategoryByName(string name, bool throwIfNotFound) { using (TransactionScope transaction = new TransactionScope(mConfiguration)) { CategoryDataStore dataStore = new CategoryDataStore(transaction); Category category = dataStore.FindByName(name); if (category == null && throwIfNotFound) { throw new NewsCategoryNotFoundException(name); } else if (category == null) { return(null); } return(category); } }
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.FindAllChildren(category.Id).Count > 0) { throw new SchemaIntegrityException("Category has child categories"); } // 2. There are no articles associated with this category. ItemDataStore ads = new ItemDataStore(transaction); if (ads.FindByCategory(category).Count > 0) { throw new SchemaIntegrityException("News items are associated with this category"); } // Delete all Access records. AccessDataStore accessDs = new AccessDataStore(transaction); IList <Access> allAccess = accessDs.FindAllByItem(category.Id); foreach (Access access in allAccess) { access.Deleted = true; accessDs.Update(access); } category.Deleted = true; category.Name += DateTimeHelper.GetCurrentTimestamp(); dataStore.Update(category); transaction.Commit(); } }
public override IList <Item> GetItems(Category category, bool recursive) { IList <Item> items = null; using (TransactionScope transaction = new TransactionScope(mConfiguration)) { ItemDataStore dataStore = new ItemDataStore(transaction); items = dataStore.FindByCategory(category); if (recursive) { CategoryDataStore ds = new CategoryDataStore(transaction); IList <Category> children = ds.FindAllChildren(category.Id); foreach (Category child in children) { IList <Item> childItems = GetItems(child, recursive); foreach (Item item in childItems) { items.Add(item); } } } } return(items); }