public async Task <ResultDTO> GetLastResultAsync(ResultRequestDTO resultModel) { var user = await _userRepository.GetUserByNameAsync(resultModel.UserName); var test = await _testRepository.GetTestDetailsAsync(resultModel.TestName); var userResult = await _resultRepository.GetLastResultAsync(user.Id.ToString(), test.Id); var result = new ResultDTO(); _mapper.Map <ResultDTO>(userResult); if (userResult != null) { result = _mapper.Map <ResultDTO>(userResult); } else { result = null; } return(result); }
public async Task <MinimizedResultDTO> GetBestResultAsync(ResultRequestDTO resultModel) { var user = await _userRepository.GetUserByNameAsync(resultModel.UserName); var test = await _testRepository.GetTestDetailsAsync(resultModel.TestName); var userResult = await _resultRepository.GetBestResultAsync(user.Id.ToString(), test.Id); var result = _mapper.Map <MinimizedResultDTO>(userResult); if (userResult != null) { result.TotalQuestions = test.MaxQuestions; result.TestName = test.Name; } else { result = null; } return(result); }
public async Task <ActionResult <MinimizedResultDTO> > GetMinimizedResult(string userName, string testName) { var resultModel = new ResultRequestDTO() { UserName = userName, TestName = testName }; var result = await _resultService.GetLastResultAsync(resultModel); if (result != null) { return(Ok(result)); } else { return(Problem( title: "Result not found", detail: "Result for this user not found", statusCode: 404)); } }