Пример #1
0
 protected async Task SetDefaultSeoValue(CreateOrEditTopicCategoryDto input)
 {
     if (input.Translations.HasData())
     {
         input.Translations.ForEach(p =>
         {
             if (p.MetaTitle.IsNullOrEmpty())
             {
                 p.MetaTitle = p.Name;
             }
             if (p.SeoSlug.IsNullOrEmpty())
             {
                 p.SeoSlug = p.Name.ToSlug();
             }
         });
     }
     if (input.MetaTitle.IsNullOrEmpty())
     {
         input.MetaTitle = input.Name;
     }
     if (input.SeoSlug.IsNullOrEmpty())
     {
         input.SeoSlug = input.Name.ToSlug();
     }
 }
Пример #2
0
        // [AbpAuthorize(PermissionNames.AdminPage_TopicCategory)]
        protected virtual async Task CreateUserAsync(CreateOrEditTopicCategoryDto input)
        {
            var entity = ObjectMapper.Map <TopicCategory>(input);

            await postCategoryRepository.InsertAndGetIdAsync(entity);

            await CurrentUnitOfWork.SaveChangesAsync();
        }
Пример #3
0
        //[AbpAuthorize(PermissionNames.AdminPage_TopicCategory)]
        protected virtual async Task UpdateAsync(CreateOrEditTopicCategoryDto input)
        {
            var entity = await postCategoryRepository.GetAll()
                         .Include(p => p.Translations)
                         .FirstOrDefaultAsync(p => p.Id == input.Id);

            entity.Translations.Clear();
            ObjectMapper.Map(input, entity);
            await postCategoryRepository.UpdateAsync(entity);
        }
Пример #4
0
        public async Task CreateOrUpdate(CreateOrEditTopicCategoryDto input)
        {
            input.GetDefaultTranslation();
            await SetDefaultSeoValue(input);

            if (input.Id != 0)
            {
                await UpdateAsync(input);
            }
            else
            {
                await CreateUserAsync(input);
            }
        }
Пример #5
0
        public async Task <CreateOrEditTopicCategoryDto> GetForEdit(int?id)
        {
            var model        = new CreateOrEditTopicCategoryDto();
            var translations = await InitTranslationsAsync();

            if (id == null)
            {
                model.Translations = translations;
                return(model);
            }

            var entity = await postCategoryRepository.GetAll()
                         .Include(p => p.Translations)
                         .FirstOrDefaultAsync(p => p.Id == id);

            entity.MapTo(model);
            model.Translations = model.Translations
                                 .Concat(translations)
                                 .DistinctBy(p => p.Language)
                                 .ToList();
            return(model);
        }