public async Task <Either <ActionResult, ThemeViewModel> > UpdateTheme(
            Guid themeId,
            ThemeSaveViewModel updated)
        {
            return(await _persistenceHelper.CheckEntityExists <Theme>(themeId)
                   .OnSuccessDo(_userService.CheckCanManageAllTaxonomy)
                   .OnSuccess(
                       async theme =>
            {
                if (_context.Themes.Any(t => t.Slug == updated.Slug && t.Id != themeId))
                {
                    return ValidationActionResult(ValidationErrorMessages.SlugNotUnique);
                }

                theme.Title = updated.Title;
                theme.Slug = updated.Slug;
                theme.Summary = updated.Summary;

                await _context.SaveChangesAsync();

                await _publishingService.TaxonomyChanged();

                return await GetTheme(theme.Id);
            }
                       ));
        }
        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);
            }
                       ));
        }
 public async Task <ActionResult <ThemeViewModel> > UpdateTheme(
     [Required] Guid themeId,
     ThemeSaveViewModel theme)
 {
     return(await _themeService
            .UpdateTheme(themeId, theme)
            .HandleFailuresOrOk());
 }
Exemplo n.º 4
0
        public async Task CreateTheme_Returns_Ok()
        {
            var request = new ThemeSaveViewModel
            {
                Title = "Test theme"
            };

            var viewModel = new ThemeViewModel
            {
                Id = Guid.NewGuid()
            };

            var themeService = new Mock <IThemeService>();

            themeService.Setup(s => s.CreateTheme(request)).ReturnsAsync(viewModel);

            var controller = new ThemeController(themeService.Object);

            var result = await controller.CreateTheme(request);

            Assert.Equal(viewModel, result.Value);
        }
 public async Task <ActionResult <ThemeViewModel> > CreateTheme(ThemeSaveViewModel theme)
 {
     return(await _themeService
            .CreateTheme(theme)
            .HandleFailuresOrOk());
 }