public async Task <ResponseTopicDto> CreateTopicAsync(Guid boardId, RequestTopicDto topic) { var topicEntity = _mapper.Map <Topic>(topic); topicEntity.Id = Guid.NewGuid(); topicEntity.BoardId = boardId; foreach (var item in topicEntity.Messages) { item.Id = Guid.NewGuid(); item.TopicId = topicEntity.Id; item.UserId = topicEntity.UserId; } var createdEntity = await _topicRepository.CreateTopicAsync(topicEntity); var responseDto = _mapper.Map <ResponseTopicDto>(createdEntity); return(responseDto); }
public async Task <ActionResult <ResponseTopicDto> > CreateTopicAsync(Guid boardId, [FromBody] RequestTopicDto topic, [FromHeader(Name = "Accept")] string mediaType) { if (!MediaTypeHeaderValue.TryParse(mediaType, out MediaTypeHeaderValue parsedMediaType)) { return(BadRequest()); } var topicDto = await _topicService.CreateTopicAsync(boardId, topic); if (topicDto == null) { return(NotFound()); } var includeLinks = parsedMediaType.SubTypeWithoutSuffix.EndsWith("hateoas", StringComparison.InvariantCultureIgnoreCase); if (includeLinks) { IEnumerable <LinkDto> links = new List <LinkDto>(); links = CreateTopicLinks(topicDto.BoardId, topicDto.Id); var topicWithLinks = _mapper.Map <ResponseTopicLinksDto>(topicDto); topicWithLinks.Links = links; return(Ok(topicWithLinks)); } return(CreatedAtRoute("GetTopic", new { boardId = topicDto.BoardId, topicId = topicDto.Id }, topicDto)); }