Beispiel #1
0
        /// <summary>
        /// Deletes a single entity collection.
        /// </summary>
        /// <param name="entityCollection">
        /// The entity collection.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events.
        /// </param>
        public void Delete(IEntityCollection entityCollection, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                if (Deleting.IsRaisedEventCancelled(new DeleteEventArgs <IEntityCollection>(entityCollection), this))
                {
                    ((EntityCollection)entityCollection).WasCancelled = true;
                    return;
                }
            }

            DeleteAllChildCollections(entityCollection);

            UpdateSiblingSortOrders(entityCollection);

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow))
                {
                    repository.Delete(entityCollection);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Deleted.RaiseEvent(new DeleteEventArgs <IEntityCollection>(entityCollection), this);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Gets a collection of <see cref="IEntityFilterGroup"/> by a collection of keys that are not associated
 /// with a product
 /// </summary>
 /// <param name="keys">
 /// The keys.
 /// </param>
 /// <param name="productKey">
 /// The product key.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IEntityFilterGroup}"/>.
 /// </returns>
 internal IEnumerable <IEntityFilterGroup> GetEntityFilterGroupsNotContainingProduct(IEnumerable <Guid> keys, Guid productKey)
 {
     using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.GetEntityFilterGroupsNotContainingProduct(keys.ToArray(), productKey));
     }
 }
Beispiel #3
0
        /// <summary>
        /// Saves a single entity collection.
        /// </summary>
        /// <param name="entityCollection">
        /// The entity collection.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        public void Save(IEntityCollection entityCollection, bool raiseEvents = true)
        {
            if (raiseEvents)
            {
                if (Saving.IsRaisedEventCancelled(new SaveEventArgs <IEntityCollection>(entityCollection), this))
                {
                    ((EntityCollection)entityCollection).WasCancelled = true;
                    return;
                }
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow))
                {
                    repository.AddOrUpdate(entityCollection);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Saved.RaiseEvent(new SaveEventArgs <IEntityCollection>(entityCollection), this);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Gets a collection of <see cref="IEntityFilterGroup"/> by a collection of keys.
 /// </summary>
 /// <param name="keys">
 /// The keys.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IEntityFilterGroup}"/>.
 /// </returns>
 internal IEnumerable <IEntityFilterGroup> GetEntityFilterGroupsByProviderKeys(IEnumerable <Guid> keys)
 {
     using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.GetEntityFilterGroupsByProviderKeys(keys.ToArray()));
     }
 }
Beispiel #5
0
 /// <summary>
 /// The get entity collections by product key.
 /// </summary>
 /// <param name="productKey">
 /// The product key.
 /// </param>
 /// <param name="isFilter">
 /// A value indicating whether the query should be for filter collections or standard "static" collections
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IEntityCollection}"/>.
 /// </returns>
 internal IEnumerable <IEntityCollection> GetEntityCollectionsByProductKey(Guid productKey, bool isFilter = false)
 {
     using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.GetEntityCollectionsByProductKey(productKey, isFilter));
     }
 }
Beispiel #6
0
 /// <summary>
 /// The get entity collections by customer key.
 /// </summary>
 /// <param name="customerKey">
 /// The customer key.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IEntityCollection}"/>.
 /// </returns>
 internal IEnumerable <IEntityCollection> GetEntityCollectionsByCustomerKey(Guid customerKey)
 {
     using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.GetEntityCollectionsByCustomerKey(customerKey));
     }
 }
Beispiel #7
0
 /// <summary>
 /// The get all.
 /// </summary>
 /// <param name="keys">
 /// The keys.
 /// </param>
 /// <returns>
 /// The <see cref="IEnumerable{IEntityCollection}"/>.
 /// </returns>
 public IEnumerable <IEntityCollection> GetAll(params Guid[] keys)
 {
     using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.GetAll(keys));
     }
 }
Beispiel #8
0
        /// <summary>
        /// The create entity collection with key.
        /// </summary>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="providerKey">
        /// The provider key.
        /// </param>
        /// <param name="name">
        /// The name.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        /// <returns>
        /// The <see cref="IEntityCollection"/>.
        /// </returns>
        internal IEntityCollection CreateEntityCollectionWithKey(Guid entityTfKey, Guid providerKey, string name, bool raiseEvents = true)
        {
            var collection = this.CreateEntityCollection(entityTfKey, providerKey, name, raiseEvents);

            if (((EntityCollection)collection).WasCancelled)
            {
                return(collection);
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow))
                {
                    repository.AddOrUpdate(collection);
                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Created.RaiseEvent(new Events.NewEventArgs <IEntityCollection>(collection), this);
            }

            return(collection);
        }
Beispiel #9
0
 /// <summary>
 /// Determines if a collection exists.
 /// </summary>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <returns>
 /// The <see cref="bool"/>.
 /// </returns>
 public bool Exists(Guid key)
 {
     using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.Exists(key));
     }
 }
Beispiel #10
0
        /// <summary>
        /// Saves a collection of entity collections.
        /// </summary>
        /// <param name="entityCollections">
        /// The entity collections.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events
        /// </param>
        public void Save(IEnumerable <IEntityCollection> entityCollections, bool raiseEvents = true)
        {
            var collectionsArray = entityCollections as IEntityCollection[] ?? entityCollections.ToArray();

            if (raiseEvents)
            {
                Saving.RaiseEvent(new SaveEventArgs <IEntityCollection>(collectionsArray), this);
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow))
                {
                    foreach (var collection in collectionsArray)
                    {
                        repository.AddOrUpdate(collection);
                    }

                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Saved.RaiseEvent(new SaveEventArgs <IEntityCollection>(collectionsArray), this);
            }
        }
Beispiel #11
0
 /// <summary>
 /// Gets <see cref="IEntityFilterGroup"/> by it's key.
 /// </summary>
 /// <param name="key">
 /// The key.
 /// </param>
 /// <returns>
 /// The <see cref="IEntityFilterGroup"/>.
 /// </returns>
 public IEntityFilterGroup GetEntityFilterGroupByKey(Guid key)
 {
     using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
     {
         return(repository.GetEntityFilterGroup(key));
     }
 }
Beispiel #12
0
        /// <summary>
        /// The child entity collection count.
        /// </summary>
        /// <param name="collectionKey">
        /// The collection key.
        /// </param>
        /// <returns>
        /// The <see cref="int"/>.
        /// </returns>
        public int ChildEntityCollectionCount(Guid collectionKey)
        {
            using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Query <IEntityCollection> .Builder.Where(x => x.ParentKey == collectionKey);

                return(repository.Count(query));
            }
        }
Beispiel #13
0
        /// <summary>
        /// Gets the count of collections managed by a provider
        /// </summary>
        /// <param name="providerKey">The provider key</param>
        /// <returns>
        /// The count of collections managed by a provider
        /// </returns>
        public int CollectionCountManagedByProvider(Guid providerKey)
        {
            using (var repostitory = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Query <IEntityCollection> .Builder.Where(x => x.ProviderKey == providerKey);

                return(repostitory.Count(query));
            }
        }
Beispiel #14
0
        /// <summary>
        /// The get root level entity collections.
        /// </summary>
        /// <param name="entityTfKey">
        /// The entity type field key.
        /// </param>
        /// <param name="providerKey">
        /// The provider Key.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IEntityCollection}"/>.
        /// </returns>
        public IEnumerable <IEntityCollection> GetRootLevelEntityCollections(Guid entityTfKey, Guid providerKey)
        {
            using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Query <IEntityCollection> .Builder.Where(x => x.ParentKey == null && x.EntityTfKey == entityTfKey && x.ProviderKey == providerKey);

                return(repository.GetByQuery(query));
            }
        }
Beispiel #15
0
        /// <summary>
        /// The exists in collection.
        /// </summary>
        /// <param name="parentKey">
        /// The parent key.
        /// </param>
        /// <param name="collectionKey">
        /// The collection key.
        /// </param>
        /// <returns>
        /// The <see cref="bool"/>.
        /// </returns>
        public bool ExistsInCollection(Guid?parentKey, Guid collectionKey)
        {
            using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Query <IEntityCollection> .Builder.Where(x => x.ParentKey == parentKey && x.Key == collectionKey);

                return(repository.Count(query) > 0);
            }
        }
Beispiel #16
0
        /// <summary>
        /// The get by provider key.
        /// </summary>
        /// <param name="providerKey">
        /// The provider key.
        /// </param>
        /// <returns>
        /// The <see cref="IEnumerable{IEntityCollection}"/>.
        /// </returns>
        public IEnumerable <IEntityCollection> GetByProviderKey(Guid providerKey)
        {
            using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Query <IEntityCollection> .Builder.Where(x => x.ProviderKey == providerKey);

                return(repository.GetByQuery(query));
            }
        }
Beispiel #17
0
        /// <summary>
        /// The get from collection.
        /// </summary>
        /// <param name="collectionKey">
        /// The collection key.
        /// </param>
        /// <param name="page">
        /// The page.
        /// </param>
        /// <param name="itemsPerPage">
        /// The items per page.
        /// </param>
        /// <param name="sortBy">
        /// The sort by.
        /// </param>
        /// <param name="sortDirection">
        /// The sort direction.
        /// </param>
        /// <returns>
        /// The <see cref="Page"/>.
        /// </returns>
        public Page <IEntityCollection> GetFromCollection(
            Guid collectionKey,
            long page,
            long itemsPerPage,
            string sortBy = "",
            SortDirection sortDirection = SortDirection.Descending)
        {
            using (var repository = RepositoryFactory.CreateEntityCollectionRepository(UowProvider.GetUnitOfWork()))
            {
                var query = Query <IEntityCollection> .Builder.Where(x => x.ParentKey == collectionKey);

                return(repository.GetPage(page, itemsPerPage, query, ValidateSortByField(sortBy), sortDirection));
            }
        }
Beispiel #18
0
        /// <summary>
        /// Deletes a collection of entity collections.
        /// </summary>
        /// <param name="entityCollections">
        /// The entity collections.
        /// </param>
        /// <param name="raiseEvents">
        /// Optional boolean indicating whether or not to raise events.
        /// </param>
        internal void Delete(IEnumerable <IEntityCollection> entityCollections, bool raiseEvents = true)
        {
            var collectionsArray = entityCollections as IEntityCollection[] ?? entityCollections.ToArray();

            if (!collectionsArray.Any())
            {
                return;
            }
            if (raiseEvents)
            {
                Deleting.RaiseEvent(new DeleteEventArgs <IEntityCollection>(collectionsArray), this);
            }

            foreach (var collection in collectionsArray)
            {
                this.DeleteAllChildCollections(collection);
            }

            using (new WriteLock(Locker))
            {
                var uow = UowProvider.GetUnitOfWork();
                using (var repository = RepositoryFactory.CreateEntityCollectionRepository(uow))
                {
                    foreach (var collection in collectionsArray)
                    {
                        repository.Delete(collection);
                    }

                    uow.Commit();
                }
            }

            if (raiseEvents)
            {
                Deleted.RaiseEvent(new DeleteEventArgs <IEntityCollection>(collectionsArray), this);
            }
        }