public void Category_Tests_Succeed() { var allCategories = _categoryService.GetFullCategoryTree(); var clothingCategory = _categoryAccountant.CreateCategoryTree("Clothing", allCategories); var shirtCategory = _categoryAccountant.CreateCategoryTree("Clothing > Shirts", allCategories); var tShirtCategory = _categoryAccountant.CreateCategoryTree("Clothing > Shirts > T-Shirts", allCategories); var tShirtCategory2 = _categoryAccountant.CreateCategoryTree("Clothing>Shirts>T-Shirts", allCategories); var tShirtCategory3 = _categoryAccountant.CreateCategoryTree("clothing>shirts > t-SHIRTS", allCategories); Assert.AreEqual(clothingCategory.Id, shirtCategory.ParentId); Assert.AreEqual(shirtCategory.Id, tShirtCategory.ParentId); Assert.AreEqual(tShirtCategory.Id, tShirtCategory2.Id); Assert.AreEqual(tShirtCategory.Id, tShirtCategory3.Id); }
public IActionResult SaveCategoryTrees(string categories) { if (categories.IsNullEmptyOrWhiteSpace()) { return(R.Fail.With("error", "Can't add empty category trees").Result); } //split the trees by new lines var categoryTrees = categories.Split('\n', StringSplitOptions.RemoveEmptyEntries); if (!categoryTrees.Any()) { return(R.Fail.With("error", "Can't add empty category trees").Result); } //get all the categories var allCategories = _categoryService.GetFullCategoryTree(); Transaction.Initiate(transaction => { foreach (var c in categoryTrees) { _categoryAccountant.CreateCategoryTree(c, allCategories); } }); return(R.Success.Result); }