public async Task FinishAsync(long scoringId) { var scoring = await _scoringRepository.GetByIdAsync(scoringId); if (scoring == null) { throw new AppErrorException(ErrorCode.ScoringNotFound); } var project = await _projectRepository.GetByIdAsync(scoring.ProjectId); if (project == null) { throw new AppErrorException(ErrorCode.ProjectNotFound); } if (!project.IsPrivate) { throw new AppErrorException(ErrorCode.ServerError, "'Finish' is allowed only for private scoring."); } var scoringResults = await _scoringContractClient.GetResultsAsync(scoring.ContractAddress); foreach (var area in scoringResults.AreaScores.Keys) { if (scoring.HasEnoughEstimatesInArea(area)) { scoring.SetScoreForArea(area, scoringResults.AreaScores[area]); } } scoring.Finish(scoringResults.Score, _clock.UtcNow); await _scoringRepository.SaveChangesAsync(); }
public async Task SubmitEstimatesAsync(long expertId, SubmitEstimateRequest request) { var scoring = await _scoringRepository.GetByProjectIdAsync(request.ProjectId); var area = request.AreaType.ToDomain(); if (!scoring.IsOfferAccepted(expertId, area)) { throw new AppErrorException(ErrorCode.AcceptedOfferNotFound); } scoring.FinishOffer(expertId, area); var scoringResults = await _scoringContractClient.GetResultsAsync(scoring.ContractAddress); var areaScore = scoringResults.AreaScores[area]; if (scoring.HasEnoughEstimatesInArea(area)) { scoring.SetScoreForArea(area, areaScore); } var project = await _projectRepository.GetByIdAsync(scoring.ProjectId); if (!project.IsPrivate && scoring.AreAllAreasCompleted()) { scoring.Finish(scoringResults.Score, _clock.UtcNow); } await _scoringRepository.SaveChangesAsync(); }