public virtual ActionResult CategoryNavigation(object Id)
        {
            int categoryId = Convert.ToInt32(Id);

            Category CategoryToNavigate = hopeLingerieEntities.Categories.FirstOrDefault(x => x.CategoryId == categoryId);
            Category ParentRootCategory = new Category();
            GetParentRootCategory(CategoryToNavigate, ref ParentRootCategory);
            currentSelection.MenuIndex = GetCategoryIdByDescription(ParentRootCategory.Description);

            List<Category> childCategories = hopeLingerieEntities.Categories.ToList<Category>().FindAll(x => x.ParentCategoryId == CategoryToNavigate.CategoryId && x.Active == true);
            List<Category> Result = new List<Category>();

            Result.AddRange(childCategories.GetRange(0, childCategories.Count));

            GetCategoriesChildsRecursive(childCategories, ref Result);

            int ParentCountProduct = 0;

            GetProductCountRecursive(CategoryToNavigate, ref ParentCountProduct);

            BulidParentCategoryHierarchy(CategoryToNavigate, ref currentSelection.BrebreadCrumbsHierarchy);

            currentSelection.CategoryTreeData.ParentCategory = CategoryToNavigate;
            currentSelection.CategoryTreeData.ParentProductsCount = ParentCountProduct;

            foreach (var cat in childCategories)
            {
                int ChildrenCountProduct = 0;

                GetProductCountRecursive(cat, ref ChildrenCountProduct);
                currentSelection.CategoryTreeData.ChildCategories.Add(cat, ChildrenCountProduct);
            }

            GetAllProductsUnderCategory(CategoryToNavigate);

            currentSelection.RootCategory = ParentRootCategory;

            currentSelection.PageNumber = 1;
            currentSelection.Action = ParentRootCategory.Description;

            return View("Categories", currentSelection);
        }
        private void GetProductCountRecursive(Category category, ref int Result)
        {
            List<Category> childCategories = hopeLingerieEntities.Categories.ToList<Category>().FindAll(x => (x.ParentCategoryId == category.CategoryId && x.Active));

            Result += hopeLingerieEntities.Products.ToList<Product>().FindAll(x => x.CategoryId == category.CategoryId && x.Active && x.Published).Count;

            foreach (Category cat in childCategories)
            {
                GetProductCountRecursive(cat, ref Result);
            }
        }
        private void PrepareNavigationSettings(Category parentCaregory)
        {
            List<Category> childCategories = hopeLingerieEntities.Categories.ToList<Category>().FindAll(x => x.ParentCategoryId == parentCaregory.CategoryId && x.Active == true);
            List<Category> Result = new List<Category>();

            Result.AddRange(childCategories.GetRange(0, childCategories.Count));

            GetCategoriesChildsRecursive(childCategories, ref Result);

            int ParentCountProduct = 0;

            GetProductCountRecursive(hopeLingerieEntities.Categories.FirstOrDefault(x => x.Description == parentCaregory.Description), ref ParentCountProduct);

            currentSelection.CategoryTreeData.ParentCategory = hopeLingerieEntities.Categories.FirstOrDefault(x => x.Description == parentCaregory.Description);
            currentSelection.CategoryTreeData.ParentProductsCount = ParentCountProduct;

            BulidParentCategoryHierarchy(parentCaregory, ref currentSelection.BrebreadCrumbsHierarchy);

            foreach (var cat in childCategories)
            {
                int ChildrenCountProduct = 0;

                GetProductCountRecursive(cat, ref ChildrenCountProduct);
                currentSelection.CategoryTreeData.ChildCategories.Add(cat, ChildrenCountProduct);

            }

            GetAllProductsUnderCategory(parentCaregory);
        }
        private void GetAllProductsUnderCategory(Category parentCaregory)
        {
            List<Category> childCategories = hopeLingerieEntities.Categories.ToList<Category>().FindAll(x => (x.ParentCategoryId == parentCaregory.CategoryId && x.Active));
            currentSelection.Products.AddRange(hopeLingerieEntities.Products.ToList<Product>().FindAll(x => x.CategoryId == parentCaregory.CategoryId && x.Active && x.Published));

            foreach (Category cat in childCategories)
            {
                GetAllProductsUnderCategory(cat);
            }
        }
 private void GetParentRootCategory(Category category, ref Category ParentCategory)
 {
     if (category.ParentCategoryId != null)
     {
         Category parentCat = hopeLingerieEntities.Categories.FirstOrDefault(x => x.CategoryId == category.ParentCategoryId && x.Active);
         GetParentRootCategory(parentCat, ref ParentCategory);
     }
     else
     {
         ParentCategory = category;
     }
 }
        private void BulidParentCategoryHierarchy(Category category, ref List<Category> Result)
        {
            Result.Add(category);

            if (category.ParentCategoryId != null)
            {
                BulidParentCategoryHierarchy(hopeLingerieEntities.Categories.ToList<Category>().FirstOrDefault(x => x.CategoryId == category.ParentCategoryId), ref Result);
            }
            else
            {
                Result.Reverse();
            }
        }
        public virtual ActionResult ProductDetail(Int32 Id)
        {
            int productId = Id;

            var product = hopeLingerieEntities.Products.SingleOrDefault(x => x.ProductId == productId && x.Active && x.Published);

            Category CategoryToNavigate = hopeLingerieEntities.Categories.FirstOrDefault(x => x.CategoryId == product.CategoryId);
            Category ParentRootCategory = new Category();
            GetParentRootCategory(CategoryToNavigate, ref ParentRootCategory);
            currentSelection.MenuIndex = GetCategoryIdByDescription(ParentRootCategory.Description);
            currentSelection.ProductSelected = product;
            BulidParentCategoryHierarchy(CategoryToNavigate, ref currentSelection.BrebreadCrumbsHierarchy);

            return View("ProductDetail", currentSelection);
        }
        public virtual ActionResult CategoryUpdate(FormCollection formCollection)
        {
            Category category = new Category();

            if (Convert.ToInt16(formCollection["CategoryId"]) > 0)
            {
                int categoryId = Convert.ToInt16(formCollection["CategoryId"]);
                category = hopeLingerieEntities.Categories.Single(x => x.CategoryId == categoryId && x.Active);
            }

            TryUpdateModel(category, formCollection);

            category.Enabled = (formCollection["IsEnabled"] == "C");

            category.Description = formCollection["Descript"];

            /* Verificar si es categoria root => no se repita el nombre */
            if ((category.ParentCategoryId == -1) || (category.ParentCategoryId == null))
            {
                var newCategory = hopeLingerieEntities.Categories.SingleOrDefault(x => x.Description == category.Description && x.CategoryId != category.CategoryId && x.Active && x.ParentCategoryId == null);

                if (newCategory != null)
                {
                    TempData["Legend"] = "Ya existe una categoría Menú con ese nombre, intente con uno distinto!";
                    return RedirectToAction("CategoryUpdate", Convert.ToInt16(formCollection["CategoryId"]));
                }
            }

            if (category.CategoryId <= 0)
            {
                if (category.ParentCategoryId == -1)
                    category.ParentCategoryId = null;

                hopeLingerieEntities.Categories.AddObject(category);
            }

            hopeLingerieEntities.SaveChanges();

            return Redirect("/BackOffice/Categories");
        }
 /// <summary>
 /// Create a new Category object.
 /// </summary>
 /// <param name="categoryId">Initial value of the CategoryId property.</param>
 /// <param name="description">Initial value of the Description property.</param>
 /// <param name="enabled">Initial value of the Enabled property.</param>
 public static Category CreateCategory(global::System.Int32 categoryId, global::System.String description, global::System.Boolean enabled)
 {
     Category category = new Category();
     category.CategoryId = categoryId;
     category.Description = description;
     category.Enabled = enabled;
     return category;
 }
 /// <summary>
 /// Deprecated Method for adding a new object to the Categories EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCategories(Category category)
 {
     base.AddObject("Categories", category);
 }