public void AddSubCategory(int mainCategoryId, string name)
 {
     CategoryEntity subCategory = new CategoryEntity();
     subCategory.BaseCategoryId = mainCategoryId;
     subCategory.Name = name;
     subCategory.Save();
 }
        /// <summary>Creates a new, empty CategoryEntity object.</summary>
        /// <returns>A new, empty CategoryEntity object.</returns>
        public override IEntity Create()
        {
            IEntity toReturn = new CategoryEntity();

            // __LLBLGENPRO_USER_CODE_REGION_START CreateNewCategory
            // __LLBLGENPRO_USER_CODE_REGION_END
            return toReturn;
        }
 public bool DeleteCategory(int mainCategoryId)
 {
     CategoryEntity mainCategory = new CategoryEntity(mainCategoryId);
     foreach (CategoryEntity item in mainCategory.Categories)
     {
         item.Delete();
     }
     return mainCategory.Delete();
 }
 /// <summary> setups the sync logic for member _category</summary>
 /// <param name="relatedEntity">Instance to set as the related entity of type entityType</param>
 private void SetupSyncCategory(IEntity relatedEntity)
 {
     if(_category!=relatedEntity)
     {
         DesetupSyncCategory(true, true);
         _category = (CategoryEntity)relatedEntity;
         this.PerformSetupSyncRelatedEntity( _category, new PropertyChangedEventHandler( OnCategoryPropertyChanged ), "Category", ProductSearchEngine.RelationClasses.StaticProductRelations.CategoryEntityUsingCategoryIdStatic, true, ref _alreadyFetchedCategory, new string[] {  } );
     }
 }
 /// <summary> Removes the sync logic for member _category</summary>
 /// <param name="signalRelatedEntity">If set to true, it will call the related entity's UnsetRelatedEntity method</param>
 /// <param name="resetFKFields">if set to true it will also reset the FK fields pointing to the related entity</param>
 private void DesetupSyncCategory(bool signalRelatedEntity, bool resetFKFields)
 {
     this.PerformDesetupSyncRelatedEntity( _category, new PropertyChangedEventHandler( OnCategoryPropertyChanged ), "Category", ProductSearchEngine.RelationClasses.StaticProductRelations.CategoryEntityUsingCategoryIdStatic, true, signalRelatedEntity, "Products", resetFKFields, new int[] { (int)ProductFieldIndex.CategoryId } );
     _category = null;
 }
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected ProductEntity(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _comments = (ProductSearchEngine.CollectionClasses.CommentCollection)info.GetValue("_comments", typeof(ProductSearchEngine.CollectionClasses.CommentCollection));
            _alwaysFetchComments = info.GetBoolean("_alwaysFetchComments");
            _alreadyFetchedComments = info.GetBoolean("_alreadyFetchedComments");

            _productKeywords = (ProductSearchEngine.CollectionClasses.ProductKeywordCollection)info.GetValue("_productKeywords", typeof(ProductSearchEngine.CollectionClasses.ProductKeywordCollection));
            _alwaysFetchProductKeywords = info.GetBoolean("_alwaysFetchProductKeywords");
            _alreadyFetchedProductKeywords = info.GetBoolean("_alreadyFetchedProductKeywords");

            _productPhotos = (ProductSearchEngine.CollectionClasses.ProductPhotoCollection)info.GetValue("_productPhotos", typeof(ProductSearchEngine.CollectionClasses.ProductPhotoCollection));
            _alwaysFetchProductPhotos = info.GetBoolean("_alwaysFetchProductPhotos");
            _alreadyFetchedProductPhotos = info.GetBoolean("_alreadyFetchedProductPhotos");

            _productSpecifications = (ProductSearchEngine.CollectionClasses.ProductSpecificationCollection)info.GetValue("_productSpecifications", typeof(ProductSearchEngine.CollectionClasses.ProductSpecificationCollection));
            _alwaysFetchProductSpecifications = info.GetBoolean("_alwaysFetchProductSpecifications");
            _alreadyFetchedProductSpecifications = info.GetBoolean("_alreadyFetchedProductSpecifications");
            _brand = (BrandEntity)info.GetValue("_brand", typeof(BrandEntity));
            if(_brand!=null)
            {
                _brand.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _brandReturnsNewIfNotFound = info.GetBoolean("_brandReturnsNewIfNotFound");
            _alwaysFetchBrand = info.GetBoolean("_alwaysFetchBrand");
            _alreadyFetchedBrand = info.GetBoolean("_alreadyFetchedBrand");

            _category = (CategoryEntity)info.GetValue("_category", typeof(CategoryEntity));
            if(_category!=null)
            {
                _category.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _categoryReturnsNewIfNotFound = info.GetBoolean("_categoryReturnsNewIfNotFound");
            _alwaysFetchCategory = info.GetBoolean("_alwaysFetchCategory");
            _alreadyFetchedCategory = info.GetBoolean("_alreadyFetchedCategory");

            _store = (StoreEntity)info.GetValue("_store", typeof(StoreEntity));
            if(_store!=null)
            {
                _store.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _storeReturnsNewIfNotFound = info.GetBoolean("_storeReturnsNewIfNotFound");
            _alwaysFetchStore = info.GetBoolean("_alwaysFetchStore");
            _alreadyFetchedStore = info.GetBoolean("_alreadyFetchedStore");
            this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
 /// <summary> Retrieves the related entity of type 'CategoryEntity', using a relation of type 'n:1'</summary>
 /// <param name="forceFetch">if true, it will discard any changes currently in the currently loaded related entity and will refetch the entity from the persistent storage</param>
 /// <returns>A fetched entity of type 'CategoryEntity' which is related to this entity.</returns>
 public virtual CategoryEntity GetSingleCategory(bool forceFetch)
 {
     if( ( !_alreadyFetchedCategory || forceFetch || _alwaysFetchCategory) && !this.IsSerializing && !this.IsDeserializing  && !this.InDesignMode)
     {
         bool performLazyLoading = this.CheckIfLazyLoadingShouldOccur(Relations.CategoryEntityUsingCategoryId);
         CategoryEntity newEntity = new CategoryEntity();
         bool fetchResult = false;
         if(performLazyLoading)
         {
             AddToTransactionIfNecessary(newEntity);
             fetchResult = newEntity.FetchUsingPK(this.CategoryId.GetValueOrDefault());
         }
         if(fetchResult)
         {
             newEntity = (CategoryEntity)GetFromActiveContext(newEntity);
         }
         else
         {
             if(!_categoryReturnsNewIfNotFound)
             {
                 RemoveFromTransactionIfNecessary(newEntity);
                 newEntity = null;
             }
         }
         this.Category = newEntity;
         _alreadyFetchedCategory = fetchResult;
     }
     return _category;
 }
        /// <summary>Private CTor for deserialization</summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
        protected CategoryEntity(SerializationInfo info, StreamingContext context)
            : base(info, context)
        {
            _categories = (ProductSearchEngine.CollectionClasses.CategoryCollection)info.GetValue("_categories", typeof(ProductSearchEngine.CollectionClasses.CategoryCollection));
            _alwaysFetchCategories = info.GetBoolean("_alwaysFetchCategories");
            _alreadyFetchedCategories = info.GetBoolean("_alreadyFetchedCategories");

            _products = (ProductSearchEngine.CollectionClasses.ProductCollection)info.GetValue("_products", typeof(ProductSearchEngine.CollectionClasses.ProductCollection));
            _alwaysFetchProducts = info.GetBoolean("_alwaysFetchProducts");
            _alreadyFetchedProducts = info.GetBoolean("_alreadyFetchedProducts");
            _category = (CategoryEntity)info.GetValue("_category", typeof(CategoryEntity));
            if(_category!=null)
            {
                _category.AfterSave+=new EventHandler(OnEntityAfterSave);
            }
            _categoryReturnsNewIfNotFound = info.GetBoolean("_categoryReturnsNewIfNotFound");
            _alwaysFetchCategory = info.GetBoolean("_alwaysFetchCategory");
            _alreadyFetchedCategory = info.GetBoolean("_alreadyFetchedCategory");
            this.FixupDeserialization(FieldInfoProviderSingleton.GetInstance(), PersistenceInfoProviderSingleton.GetInstance());
            // __LLBLGENPRO_USER_CODE_REGION_START DeserializationConstructor
            // __LLBLGENPRO_USER_CODE_REGION_END
        }
        public CategoryCollection GetRelatedSubCategories(int subCatId)
        {
            CategoryEntity category = new CategoryEntity(subCatId);

            return GetSubCategories(category.Category.Id);
        }
 public int GetMainCatehoryIdBySubCategoryId(int subCatId)
 {
     CategoryEntity category = new CategoryEntity(subCatId);
     return category.Category.Id;
 }
        public bool DeleteSubCategory(int subCategoryId)
        {
            CategoryEntity subCategory = new CategoryEntity(subCategoryId);

            return subCategory.Delete();
        }
 public void AddMainCategory(string name)
 {
     CategoryEntity mainCategory = new CategoryEntity();
     mainCategory.Name = name;
     mainCategory.Save();
 }