public ActionResult Add(CategoryModel model)
        {
            if (!_permissionService.Authorize(PermissionProvider.ManageCategories))
                return AccessDeniedView();

            Category category = new Category
            {
                CreatedBy = _workContext.CurrentUser.Id,
                LastModifiedBy = _workContext.CurrentUser.Id
            };

            if (ModelState.IsValid)
            {
                try
                {
                    category.Name = model.Name;
                    _categoryService.InsertCategory(category);

                    SuccessNotification("The category details have been added successfully.");
                    return RedirectToAction("index");
                }
                catch (Exception)
                {
                    ErrorNotification("An error occurred saving the category details, please try again.");
                }
            }

            PrepareBreadcrumbs();
            AddBreadcrumb("Add New Category", null);

            return View(model);
        }
        public static CategoryModel ToModel(this Category entity)
        {
            if (entity == null)
                return null;

            var model = new CategoryModel
            {
                Active = entity.Active,
                CreatedBy = entity.CreatedBy,
                CreatedDate = entity.CreatedDate,
                Deleted = entity.Deleted,
                Id = entity.Id,
                LastModifiedBy = entity.LastModifiedBy,
                LastModifiedDate = entity.LastModifiedDate,
                Name = entity.Name
            };

            return model;
        }
        public ActionResult Hide(CategoryModel model)
        {
            if (!_permissionService.Authorize(PermissionProvider.ManageCategories))
                return AccessDeniedView();

            // get the category
            var category = _categoryService.GetCategoryById(model.Id);

            // check we have a category and they are not deleted
            if (category == null || category.Deleted)
                return RedirectToAction("index");
            category.LastModifiedBy = _workContext.CurrentUser.Id;

            try
            {
                category.Active = !category.Active;
                _categoryService.UpdateCategory(category);

                SuccessNotification(category.Active ? "The category has been shown successfully." : "The category has been hidden successfully.");

                return RedirectToAction("edit", category.Id);
            }
            catch (Exception)
            {
                ErrorNotification("An error occurred hiding the category, please try again.");
            }

            PrepareBreadcrumbs();
            AddBreadcrumb("Edit Category", null);

            return View(model);
        }
        public ActionResult Edit(CategoryModel model)
        {
            if (!_permissionService.Authorize(PermissionProvider.ManageCategories))
                return AccessDeniedView();

            // get the category
            var category = _categoryService.GetCategoryById(model.Id);

            // check we have a category and they are not deleted
            if (category == null || category.Deleted)
                return RedirectToAction("index");
            category.LastModifiedBy = _workContext.CurrentUser.Id;

            if (ModelState.IsValid)
            {
                try
                {
                    category.Name = model.Name;
                    _categoryService.UpdateCategory(category);

                    SuccessNotification("The category details have been updated successfully.");
                    return RedirectToAction("edit", category.Id);
                }
                catch (Exception)
                {
                    ErrorNotification("An error occurred saving the category details, please try again.");
                }
            }
            else
            {
                ErrorNotification("We were unable to make the change, please review the form and correct the errors.");
            }

            PrepareBreadcrumbs();
            AddBreadcrumb(category.Name, null);

            return View(model);
        }