Beispiel #1
0
        public async Task <IActionResult> EditTestAnalysis([FromRoute] Guid testAnalysisId,
                                                           [FromBody] ReplaceTestAnalysisDto testAnalysisDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var testExists = await _context.TestAnalyses.AnyAsync(analysis => analysis.Id == testAnalysisId);

            if (!testExists)
            {
                return(NotFound());
            }

            var testAnalysis = await _context.TestAnalyses.AsNoTracking().SingleAsync(x => x.Id == testAnalysisId);

            testAnalysis.Description     = testAnalysisDto.Description;
            testAnalysis.EndValue        = testAnalysisDto.EndValue.GetValueOrDefault();
            testAnalysis.LimpingSeverity = testAnalysisDto.LimpingSeverity.GetValueOrDefault();
            await _testAnalysesService.EditTestAnalysis(testAnalysis);

            var response = new GetTestAnalysisResponse(testAnalysis, LinkGenerator.Analysis.Replace(testAnalysis.Id.ToString(), "self"));

            return(Ok(response));
        }
Beispiel #2
0
        public async Task <IActionResult> UpsertTestAnalysis([FromRoute] Guid testId, [FromBody] ReplaceTestAnalysisDto testAnalysisDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var testExists = await _context.LimpingTests.AnyAsync(test => test.Id == testId);

            if (!testExists)
            {
                return(NotFound());
            }

            // Convert it to db model
            var testAnalysis = new TestAnalysis
            {
                Description     = testAnalysisDto.Description,
                EndValue        = testAnalysisDto.EndValue.GetValueOrDefault(),
                LimpingSeverity = testAnalysisDto.LimpingSeverity.GetValueOrDefault(),
                LimpingTestId   = testId,
            };

            // Replace it
            await _testAnalysesService.ReplaceTestAnalysis(testId, testAnalysis);

            // Convert it to HAL
            var response = new GetTestAnalysisResponse(testAnalysis, LinkGenerator.Analysis.Edit(testAnalysis.Id.ToString(), "self"));

            return(Ok(response));
        }