public IActionResult CreateLine([FromBody] LineDto LineDto) { //null Dto if (LineDto == null) { return(BadRequest(ModelState)); } //if state not valid if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // all correct! create the new network ,return it using the mapper!-->create the model var newLine = _mapper.Map <Line>(LineDto); //check if record was created successfully or not if (!_LineRepository.CreateLine(newLine)) { ModelState.AddModelError("", $"Something is wrong with the creation of the record{newLine.Id}"); return(StatusCode(500, ModelState)); } //return the created object instead of a simple ok answer return(CreatedAtRoute("GetLine", new { LineId = newLine.Id }, newLine)); }