コード例 #1
0
        public async Task <NewsCategory> CreateCategoryAsync(NewsCategory category)
        {
            VerifyManagementPermission();

            if (category == null)
            {
                throw new GraException("You must provide a category to add.");
            }

            category.Name      = category.Name.Trim();
            category.IsDefault = false;
            category.SiteId    = GetCurrentSiteId();

            return(await _newsCategoryRepository.AddSaveAsync(GetClaimId(ClaimType.UserId), category));
        }
コード例 #2
0
        public async Task EnsureDefaultCategoryAsync()
        {
            var sites = await _siteRepository.GetAllAsync();

            foreach (var site in sites)
            {
                var defaultCategory = await _newsCategoryRepository
                                      .GetDefaultCategoryAsync(site.Id);

                if (defaultCategory == null)
                {
                    var category = new NewsCategory
                    {
                        IsDefault = true,
                        Name      = "News",
                        SiteId    = site.Id
                    };

                    await _newsCategoryRepository.AddSaveAsync(-1, category);
                }
            }
        }