protected void btnDelete_Click(object sender, EventArgs e) { if (Page.IsValid) { SubCategory.Delete(SubCategoryId); string url = "SubCategories.aspx?message-success=" + CategoriesStrings.GetText(@"MessageSubCategoryDeleted"); Response.Redirect(url, true); } }
protected void btnDelete_Click(object sender, EventArgs e) { if (Page.IsValid) { SubCategoryCollection coll = ProductController.GetAllSubCategory(CategoryId); if (coll.Count > 0) { foreach (SubCategory subCategory in coll) { SubCategory.Delete(subCategory.SubCategoryId); } } Category.Delete(CategoryId); string url = "Categories.aspx?message-success=" + CategoriesStrings.GetText(@"MessageCategoryDeleted"); Response.Redirect(url, true); } }
private static void TestCategories(MyUser user) { Console.WriteLine("Test the category and subcategory methods"); Album myAlbumInCategory = null; Category myCategory = null; SubCategory mySubCategory = null; SubCategory mySubCategoryNew = null; Album myAlbumInSubCategory = null; Album myAlbumInCategory2 = null; try { // Create a category myCategory = user.CreateCategory("TestCategory"); Console.WriteLine("Created category {0}", myCategory.Name); } catch (Exception e) { Console.WriteLine(e); } try { // Create a subcategory in a category mySubCategory = myCategory.CreateSubCategory("TestSubCategory"); Console.WriteLine("Created subcategoy {0} in category {1}", mySubCategory.Name, myCategory.Name); } catch (Exception e) { Console.WriteLine(e); } try { // Creating an album in a category myAlbumInCategory = myCategory.CreateAlbum("TestAlbumInCategory"); Console.WriteLine("Created album {0} in category {1}", myAlbumInCategory.Title, myCategory.Name); } catch (Exception e) { Console.WriteLine(e); } try { // Creating an album in a subcategory myAlbumInSubCategory = mySubCategory.CreateAlbum("TestAlbumInSubCategory"); Console.WriteLine("Created album {0} in the subcategory {1}", myAlbumInSubCategory.Title, mySubCategory.Name); } catch (Exception e) { Console.WriteLine(e); } try { List <Category> myCategoriesList = null; // Retrieves a list of categories for the user myCategoriesList = user.GetCategories(); foreach (var x in myCategoriesList) { Console.WriteLine(x.Name); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); try { // Renaming a category myCategory.Rename("TestCategoryRenamed"); Console.WriteLine("TestCategory is renamed to " + myCategory.Name); } catch (Exception e) { Console.WriteLine(e); } // Create a subcategory within a category try { mySubCategoryNew = myCategory.CreateSubCategory("TestSubCategoryNew"); Console.WriteLine(mySubCategoryNew.Name); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Get the subcategories for a category try { var mySubCategoriesList = myCategory.GetSubCategories(); Console.WriteLine(myCategory.Name + " - " + myCategory.SubCategories.Count); foreach (var x in mySubCategoriesList) { Console.WriteLine(x.Name); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Get all the subcategories that the user has try { var mySubCategoriesListAll = user.GetAllSubCategories(); foreach (var x in mySubCategoriesListAll) { Console.WriteLine(x.Name); } } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Rename a subcategory try { mySubCategoryNew.Rename("TestSubCategoryNewChangedName"); Console.WriteLine("TestSubCategoryNew is renamed to " + mySubCategoryNew.Name); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); // Deleting a subcategory try { mySubCategoryNew.Delete(); } catch (Exception e) { Console.WriteLine(e); } // Creating an album in a category try { Console.WriteLine(myCategory.Albums.Count); myAlbumInCategory2 = myCategory.CreateAlbum("TestAlbumInCategory2"); Console.WriteLine(); Console.WriteLine(myCategory.Albums.Count); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); try { // Deleting that album myAlbumInCategory2.Delete(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); try { myAlbumInCategory.Delete(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); try { myAlbumInSubCategory.Delete(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); try { myCategory.Delete(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); try { mySubCategory.Delete(); } catch (Exception e) { Console.WriteLine(e); } Console.WriteLine(); }