public async Task <ActionResult <TopicViewModel> > CreateTopic( TopicSaveViewModel topic) { return(await _topicService .CreateTopic(topic) .HandleFailuresOrOk()); }
public async Task <Either <ActionResult, TopicViewModel> > UpdateTopic( Guid topicId, TopicSaveViewModel updated) { return(await _userService.CheckCanManageAllTaxonomy() .OnSuccess(() => _persistenceHelper.CheckEntityExists <Topic>(topicId)) .OnSuccessDo(() => ValidateSelectedTheme(updated.ThemeId)) .OnSuccess( async topic => { if (_contentContext.Topics.Any( t => t.Slug == updated.Slug && t.Id != topicId && t.ThemeId == updated.ThemeId )) { return ValidationActionResult(ValidationErrorMessages.SlugNotUnique); } topic.Title = updated.Title; topic.Slug = updated.Slug; topic.ThemeId = updated.ThemeId; _contentContext.Topics.Update(topic); await _contentContext.SaveChangesAsync(); await _publishingService.TaxonomyChanged(); return await GetTopic(topic.Id); } )); }
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); } )); }
public async Task <ActionResult <TopicViewModel> > UpdateTopic( Guid topicId, TopicSaveViewModel topic) { return(await _topicService .UpdateTopic(topicId, topic) .HandleFailuresOrOk()); }
public async Task CreateTopic_Returns_Ok() { var request = new TopicSaveViewModel { Title = "Test topic", ThemeId = Guid.NewGuid() }; var viewModel = new TopicViewModel { Id = Guid.NewGuid() }; var topicService = new Mock <ITopicService>(); topicService.Setup(s => s.CreateTopic(request)).ReturnsAsync(viewModel); var controller = new TopicController(topicService.Object); var result = await controller.CreateTopic(request); Assert.Equal(viewModel, result.Value); }