public async Task <ActionResult <Topic> > PostTopic(CreateNewTopic topic) { System.Diagnostics.Debug.WriteLine($"PostTopic {topic.Name} with parent {topic.ParentTopicId}"); var newTopic = await _topicService.CreateTopicAsync(topic); return(CreatedAtAction(nameof(GetTopic), new { id = newTopic.Id }, newTopic)); }
public async Task <Topic> CreateTopicAsync(CreateNewTopic topicToCreate) { var parentTopic = await GetTopicAsync(topicToCreate.ParentTopicId); if (parentTopic == null) { throw new NotFoundException($"Parent topic with id ({topicToCreate.ParentTopicId}) does not exist"); } var newTopic = topicToCreate.CreateTopic(); await _schedulearnContext.Topics.AddAsync(newTopic); await _schedulearnContext.SaveChangesAsync(); return(newTopic); }