public async Task <bool> CreateTopicAsync(TopicForCreate topicForCreate) { try { var topic = _mapper.Map <Topic>(topicForCreate); _context.Topics.Add(topic); await _context.SaveChangesAsync(); return(true); } catch (Exception ex) { return(false); } }
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)); }