Example #1
0
        public ActionResult <TopicDto> CreateTopicForAuthor(
            int authorId, TopicForCreationDto topic)
        {
            if (!_internetDiscussionRepository.AuthorExists(authorId))
            {
                Logger.GetLogger().LogNonExistingAuthor(authorId);
                return(NotFound());
            }

            var topicEntity = _mapper.Map <Entities.Topic>(topic);

            _internetDiscussionRepository.AddTopic(authorId, topicEntity);
            _internetDiscussionRepository.Save();

            var topicToReturn = _mapper.Map <TopicDto>(topicEntity);

            return(CreatedAtRoute("GetTopicForAuthor",
                                  new { authorId = authorId, topicId = topicToReturn.Id },
                                  topicToReturn));
        }
Example #2
0
        public IActionResult CreateTopic([FromBody] TopicForCreationDto topicForCreation)
        {
            if (topicForCreation == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var topicEntity = Mapper.Map <Topic>(topicForCreation);

            noterRepository.CreateTopic(topicEntity);

            noterRepository.Save();

            return(Ok()); // TO DO - to be implemented created at route
        }