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

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

                await _context.SaveChangesAsync();

                await _publishingService.TaxonomyChanged();

                return await GetTheme(saved.Entity.Id);
            }
                       ));
        }
Example #2
0
        public async Task <Either <ActionResult, ThemeViewModel> > UpdateTheme(
            Guid themeId,
            SaveThemeViewModel updatedTheme)
        {
            return(await _persistenceHelper.CheckEntityExists <Theme>(themeId)
                   .OnSuccessDo(_userService.CheckCanManageAllTaxonomy)
                   .OnSuccess(
                       async theme =>
            {
                if (_context.Themes.Any(t => t.Slug == updatedTheme.Slug && t.Id != themeId))
                {
                    return ValidationActionResult(ValidationErrorMessages.SlugNotUnique);
                }

                theme.Title = updatedTheme.Title;
                theme.Slug = updatedTheme.Slug;
                theme.Summary = updatedTheme.Summary;

                await _context.SaveChangesAsync();

                await _publishingService.TaxonomyChanged();

                return await GetTheme(theme.Id);
            }
                       ));
        }
Example #3
0
 public async Task <ActionResult <ThemeViewModel> > UpdateTheme(
     [Required] Guid themeId,
     SaveThemeViewModel theme)
 {
     return(await _themeService
            .UpdateTheme(themeId, theme)
            .HandleFailuresOrOk());
 }
Example #4
0
        public async Task CreateTheme_Returns_Ok()
        {
            var request = new SaveThemeViewModel
            {
                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);
        }
Example #5
0
 public async Task <ActionResult <ThemeViewModel> > CreateTheme(SaveThemeViewModel theme)
 {
     return(await _themeService
            .CreateTheme(theme)
            .HandleFailuresOrOk());
 }