public async Task <IActionResult> AddPlane([FromBody] PlaneDTO plane) { if (!ModelState.IsValid) { return(BadRequest() as IActionResult); } if (!plane.PlaneTypeId.HasValue) { return(BadRequest("Plane type have to be defined!") as IActionResult); } //var targetType = service.GetPlaneTypeInfo(plane.PlaneTypeId.Value); //if (targetType == null) // return NotFound($"Plane type with id = {plane.PlaneTypeId} not found!Plane not added!"); //var newPlane = mapper.Map<Plane>(plane); //newPlane.Type = targetType; var entity = await service.AddPlaneAsync(mapper.Map <Plane>(plane)); return(entity == null?StatusCode(409) as IActionResult : Created($"{Request?.Scheme}://{Request?.Host}{Request?.Path}{entity.Id}", mapper.Map <PlaneDTO>(entity))); }