public JsonResult Post([FromBody] ContractHeaderViewModel viewModel) { try { if (ModelState.IsValid) { var newHeader = Mapper.Map <ContractHeader>(viewModel); _logger.LogInformation("Attemping to save new Contract Header"); _repository.AddContractHeader(newHeader); if (_repository.SaveAll()) { Response.StatusCode = (int)HttpStatusCode.Created; return(Json(Mapper.Map <ContractHeaderViewModel>(newHeader))); } } } catch (Exception ex) { _logger.LogError("Failed to save new Contract Header", ex); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(Json(new { Message = ex.Message, Text = "Does not work!" })); } return(Json("Failed!")); }