public async Task <IActionResult> Put(int id, [FromBody] TestDataL1Model sInfo) { try { var oldTestDataInfo = await _repo.GetTestDataById(id); if (oldTestDataInfo == null) { return(NotFound($"Could not find a Test Data Info with an ID of {id}")); } //Map Model to the old station info oldTestDataInfo.SerialNumber = sInfo.SerialNumber ?? oldTestDataInfo.SerialNumber; oldTestDataInfo.CustomerSerialNumber = sInfo.CustomerSerialNumber ?? oldTestDataInfo.CustomerSerialNumber; oldTestDataInfo.PartNumber = sInfo.PartNumber ?? oldTestDataInfo.PartNumber; if (await _repo.SaveChangesAsync()) { return(Ok(oldTestDataInfo)); } return(BadRequest("Couldn't update StationInfo")); } catch (Exception ex) { return(BadRequest("Couldn't update StationInfo")); } }
public async Task <IActionResult> Post([FromBody] TestDataL1Model model) { try { var testData = _mapper.Map <TestDataL1>(model); _repo.Add(testData); if (await _repo.SaveChangesAsync()) { var newUri = Url.Link("GetTestById", new { id = model.TestDataId }); return(Created(newUri, _mapper.Map <TestDataL1>(testData))); } return(Ok()); } catch (Exception ex) { return(BadRequest("Not Found, " + ex.Message)); } }