public override IList <Item> GetItemsByOwner(string owner)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         ItemDataStore dataStore = new ItemDataStore(transaction);
         return(dataStore.FindByOwner(owner));
     }
 }
 public override IList <Item> GetItems()
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         ItemDataStore dataStore = new ItemDataStore(transaction);
         return(dataStore.FindAllItems());
     }
 }
 public override IList <Item> GetItemsByGroup(string groupId)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         ItemDataStore dataStore = new ItemDataStore(transaction);
         return(dataStore.FindByGroup(groupId));
     }
 }
 public override Item GetItem(string id)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         ItemDataStore dataStore = new ItemDataStore(transaction);
         return(dataStore.FindByKey(id));
     }
 }
 public override void UpdateItem(Item item)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         ItemDataStore dataStore = new ItemDataStore(transaction);
         dataStore.Update(item);
         transaction.Commit();
     }
 }
 public override IList <Item> FindItems(Filter <string> categoryName,
                                        Filter <string> tag,
                                        DateTime?fromDate, DateTime?toDate,
                                        PagingInfo paging)
 {
     using (TransactionScope transaction = new TransactionScope(mConfiguration))
     {
         ItemDataStore dataStore = new ItemDataStore(transaction);
         return(dataStore.FindByFields(categoryName, tag, fromDate, toDate, paging));
     }
 }
        public override IList <Item> GetPublishedItems(Category category, bool recursive)
        {
            IList <Item> publishedItems = null;

            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ItemDataStore dataStore = new ItemDataStore(transaction);
                publishedItems = dataStore.FindPublishedByCategory(category);
            }
            return(publishedItems);
        }
        public override Item CreateItem(Category category, string owner,
                                        string title, string description, string url, string urlName,
                                        DateTime newsDate, bool acknowledge, bool approve, string groups,
                                        Attachment.FileInfo attachment, DateTime?expiry, ItemApprovalStatus approvalStatus)
        {
            using (TransactionScope transaction = new TransactionScope(mConfiguration))
            {
                ItemDataStore dataStore = new ItemDataStore(transaction);

                Item item = new Item(category, owner, title, description, url, urlName, newsDate, expiry, approvalStatus);
                item.Tag        = acknowledge.ToString() + ":" + approve.ToString();
                item.Groups     = groups;
                item.Attachment = attachment;

                dataStore.Insert(item);
                transaction.Commit();
                return(item);
            }
        }
        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);
        }