public JsonResult Post(int id, [FromBody] TopicViewModel vm) { try { if (ModelState.IsValid) { var newTopic = Mapper.Map <Topic>(vm); _themeRepository.AddTopic(id, newTopic); if (_themeRepository.SaveAll()) { Response.StatusCode = (int)HttpStatusCode.Created; return(Json(Mapper.Map <TopicViewModel>(newTopic))); } } } catch (Exception ex) { _logger.LogError(ex.Message); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { ex.Message })); } Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = "Validation Failed.", ModelState })); }