Ejemplo n.º 1
0
        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);
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateTopic([FromBody] TopicForCreate input)
        {
            if (ModelState.IsValid)
            {
                var result = await _topicRepository.CreateTopicAsync(input);

                if (result)
                {
                    return(Ok(new
                    {
                        message = "success",
                        StatusCode = 201
                    }));
                }

                return(BadRequest(new
                {
                    message = "fail"
                }));
            }

            return(BadRequest(ModelState));
        }