public async Task <IActionResult> Create([FromBody] CreateLimpingTestDto createDto) { if (!ModelState.IsValid || string.IsNullOrWhiteSpace(createDto.TestData)) { return(BadRequest(ModelState)); } var userExists = await _context.AppUsers.AnyAsync(user => user.Id == createDto.AppUserId); if (!userExists) { return(NotFound("The user was not found")); } var testAnalysisDto = createDto.TestAnalysis; // Convert it to database model var testAnalysis = new TestAnalysis { Description = testAnalysisDto.Description, EndValue = testAnalysisDto.EndValue.GetValueOrDefault(), LimpingSeverity = testAnalysisDto.LimpingSeverity.GetValueOrDefault(), }; // Save it var createdTest = await _limpingTestsService.InsertTest(createDto.AppUserId, createDto.TestData, testAnalysis); // Create the HAL response var response = new GetLimpingTestResponse(createdTest, selfLink: LinkGenerator.LimpingTests.Create("self")); return(Ok(response)); }
public async Task <IActionResult> GetById([FromRoute] Guid limpingTestId) { var exists = await _context.LimpingTests.AnyAsync(lt => lt.Id == limpingTestId); if (!exists) { return(NotFound()); } // Create the HAL response with links var limpingTest = await _limpingTestsService.GetById(limpingTestId); var response = new GetLimpingTestResponse(limpingTest); return(Ok(response)); }
public async Task <IActionResult> Edit([FromRoute] Guid testId, [FromBody] EditLimpingTestDto editTestDto) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var exists = await _context.LimpingTests.AnyAsync(lt => lt.Id == testId); if (!exists) { return(NotFound()); } var testAnalysisDto = editTestDto.TestAnalysis; // Convert it to database model TestAnalysis testAnalysis = null; if (testAnalysisDto != null) { testAnalysis = new TestAnalysis { Description = testAnalysisDto.Description, EndValue = testAnalysisDto.EndValue.GetValueOrDefault(), LimpingSeverity = testAnalysisDto.LimpingSeverity.GetValueOrDefault(), LimpingTestId = testId }; } // Save it var edited = await _limpingTestsService.EditTest(testId, editTestDto.TestData, testAnalysis); // Create HAL response var response = new GetLimpingTestResponse(edited, selfLink: LinkGenerator.LimpingTests.Edit(edited.Id.ToString(), "self")); return(Ok(response)); }