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);
        }
        /// <summary>
        /// Delete a category
        /// </summary>
        /// <param name="category">Category</param>
        public void DeleteCategory(Category category)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            if (category.Deleted)
                return;

            _categoryRepository.Delete(category);

            ClearCache();
        }
        public static Category ToEntity(this CategoryModel model)
        {
            if (model == null)
                return null;

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

            return entity;
        }
        /// <summary>
        /// Updates the category
        /// </summary>
        /// <param name="category">Category</param>
        public void UpdateCategory(Category category)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            category.LastModifiedDate = DateTime.Now;

            _categoryRepository.Update(category);

            ClearCache();
        }
        /// <summary>
        /// Insert a category
        /// </summary>
        /// <param name="category">category</param>
        public void InsertCategory(Category category)
        {
            if (category == null)
                throw new ArgumentNullException("category");

            category.Active = true;
            category.CreatedDate = DateTime.Now;
            category.Deleted = false;
            category.LastModifiedDate = DateTime.Now;

            _categoryRepository.Insert(category);

            ClearCache();
        }
        private CategoryModel PrepareListCategoryModel(Category category)
        {
            var model = category.ToModel();

            model.Actions.Add(new ModelActionLink
            {
                Alt = "Edit",
                Icon = Url.Content("~/Areas/Admin/Content/images/icon-edit.png"),
                Target = Url.Action("edit", new { id = category.Id })
            });

            model.Actions.Add(new DeleteActionLink(category.Id, Search, Page));

            return model;
        }
        private void InstallCategories()
        {
            var categories = new List<string>
            {
                "Arts & Culture",
                "Children & Youth Education",
                "Cleaning",
                "Decorating",
                "Empty Shops",
                "Environment",
                "Gardening",
                "Fixing",
                "Fundraising",
                "Making",
                "Meeting",
                "Repairing",
                "Technology"
            };

            foreach (var name in categories)
            {
                var category = new Category
                {
                    Active = true,
                    CreatedDate = DateTime.Now,
                    Deleted = false,
                    LastModifiedDate = DateTime.Now,
                    Name = name
                };

                _categoryRepository.Insert(category);
            }
        }