public IActionResult CreateValuePair(int chartId, [FromBody] ValuePairForCreationDto valuePair) { if (valuePair == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (!_chartRepository.ChartExists(chartId)) { return(NotFound()); } var mapValuePair = Mapper.Map <Entities.ValuePair>(valuePair); _chartRepository.AddValuePairForChart(chartId, mapValuePair); if (!_chartRepository.Save()) { return(StatusCode(500, "A problem happened while handling your request.")); } var createdValuePairToReturn = Mapper.Map <ValuePairDto>(mapValuePair); return(CreatedAtRoute("GetValuePair", new { chartId, id = createdValuePairToReturn.Id }, createdValuePairToReturn)); }