public async Task <Either <ActionResult, ThemeViewModel> > CreateTheme(ThemeSaveViewModel created)
        {
            return(await _userService.CheckCanManageAllTaxonomy()
                   .OnSuccess(
                       async _ =>
            {
                if (_context.Themes.Any(theme => theme.Slug == created.Slug))
                {
                    return ValidationActionResult(ValidationErrorMessages.SlugNotUnique);
                }

                var saved = await _context.Themes.AddAsync(
                    new Theme
                {
                    Slug = created.Slug,
                    Summary = created.Summary,
                    Title = created.Title,
                }
                    );

                await _context.SaveChangesAsync();

                await _publishingService.TaxonomyChanged();

                return await GetTheme(saved.Entity.Id);
            }
                       ));
        }
Пример #2
0
        public async Task <Either <ActionResult, TopicViewModel> > CreateTopic(TopicSaveViewModel created)
        {
            return(await _userService.CheckCanManageAllTaxonomy()
                   .OnSuccessDo(() => ValidateSelectedTheme(created.ThemeId))
                   .OnSuccess(
                       async _ =>
            {
                if (_contentContext.Topics.Any(
                        topic => topic.Slug == created.Slug &&
                        topic.ThemeId == created.ThemeId
                        ))
                {
                    return ValidationActionResult(ValidationErrorMessages.SlugNotUnique);
                }

                var saved = await _contentContext.Topics.AddAsync(
                    new Topic
                {
                    Title = created.Title,
                    Slug = created.Slug,
                    ThemeId = created.ThemeId,
                }
                    );

                await _contentContext.SaveChangesAsync();

                await _publishingService.TaxonomyChanged();

                return await GetTopic(saved.Entity.Id);
            }
                       ));
        }