public async Task <Category> InitializeAsync()
        {
            // TODO: cache the default entity.
            var defaultCategory = new Category();

            // Set the first template as the default one.
            var firstTemplate = (await _categoryTemplateService.GetAllCategoryTemplatesAsync()).FirstOrDefault();

            if (firstTemplate != null)
            {
                defaultCategory.CategoryTemplateId = firstTemplate.Id;
            }

            //default values
            defaultCategory.PageSize         = _catalogSettings.DefaultCategoryPageSize;
            defaultCategory.PageSizeOptions  = _catalogSettings.DefaultCategoryPageSizeOptions;
            defaultCategory.Published        = true;
            defaultCategory.IncludeInTopMenu = true;
            defaultCategory.AllowCustomersToSelectPageSize = true;

            defaultCategory.CreatedOnUtc = DateTime.UtcNow;
            defaultCategory.UpdatedOnUtc = DateTime.UtcNow;

            return(defaultCategory);
        }
        /// <summary>
        /// Prepare paged category template list model
        /// </summary>
        /// <param name="searchModel">Category template search model</param>
        /// <returns>Category template list model</returns>
        public virtual async Task <CategoryTemplateListModel> PrepareCategoryTemplateListModelAsync(CategoryTemplateSearchModel searchModel)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get category templates
            var categoryTemplates = (await _categoryTemplateService.GetAllCategoryTemplatesAsync()).ToPagedList(searchModel);

            //prepare grid model
            var model = new CategoryTemplateListModel().PrepareToGrid(searchModel, categoryTemplates,
                                                                      () => categoryTemplates.Select(template => template.ToModel <CategoryTemplateModel>()));

            return(model);
        }
Exemple #3
0
        public virtual async Task <IActionResult> CategoryTemplateDelete(int id)
        {
            if (!await _permissionService.AuthorizeAsync(StandardPermissionProvider.ManageMaintenance))
            {
                return(AccessDeniedView());
            }

            if ((await _categoryTemplateService.GetAllCategoryTemplatesAsync()).Count == 1)
            {
                return(ErrorJson(await _localizationService.GetResourceAsync("Admin.System.Templates.NotDeleteOnlyOne")));
            }

            //try to get a category template with the specified id
            var template = await _categoryTemplateService.GetCategoryTemplateByIdAsync(id)
                           ?? throw new ArgumentException("No template found with the specified id");

            await _categoryTemplateService.DeleteCategoryTemplateAsync(template);

            return(new NullJsonResult());
        }