public async Task <IActionResult> CreateTestResult([FromBody] TestResultResource resource)
        {
            var testResult = _mapper.Map <TestResultResource, TestResult>(resource);

            _repository.Add(testResult);
            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <TestResult, TestResultResource>(testResult);

            return(Ok(result));
        }
Exemple #2
0
        public async Task <IActionResult> UpdateTestResult(long id, [FromBody] TestResultResource testResultResource)
        {
            var testResult = await _repository.Get(id);

            if (testResult == null)
            {
                return(NotFound());
            }

            var result = _mapper.Map <TestResultResource, TestResult>(testResultResource, testResult);
            await _unitOfWork.CompleteAsync();

            return(Ok(result));
        }
        public async Task <IActionResult> UpdateOrInsertTestResult([FromBody] TestResultResource testResultResource)
        {
            var testResult = _mapper.Map <TestResultResource, TestResult>(testResultResource);

            if (testResultResource.Id == null)
            {
                _repository.Add(testResult);
            }
            else
            {
                _repository.Update(testResult);
            }
            await _unitOfWork.CompleteAsync();

            var result = _mapper.Map <TestResult, TestResultResource>(testResult);

            return(Ok(result));
        }
Exemple #4
0
        public async Task <IActionResult> CreateTestResult([FromBody] TestResultResource testResultResource)
        {
            var testResult   = _mapper.Map <TestResultResource, TestResult>(testResultResource);
            var existsResult = await _repository.GetIfExists(testResult);

            if (existsResult == null)
            {
                _repository.Add(testResult);
            }
            else
            {
                testResult = _mapper.Map <TestResultResource, TestResult>(testResultResource, existsResult);
                _repository.Update(testResult);
            }

            var result = _mapper.Map <TestResult, TestResultResource>(testResult);
            await _unitOfWork.CompleteAsync();

            return(Ok(result));
        }