Esempio n. 1
0
        private async Task <long> CreateScoringAsync(
            Project project,
            ScoringInfo scoringInfo)
        {
            var contractAddress = await _scoringsRegistryContractClient.GetScoringAddressAsync(project.ExternalId);

            var areaScorings = await _scoringsRegistryContractClient.GetRequiredExpertsCountsAsync(project.ExternalId);

            var offers = await CreateOffersAsync(scoringInfo.Offers);

            var scoring = new Scoring(
                project.Id,
                contractAddress,
                _clock.UtcNow,
                scoringInfo.AcceptingDeadline,
                scoringInfo.ScoringDeadline,
                areaScorings.Select(x => new AreaScoring {
                AreaId = x.Area, ExpertsCount = x.Count
            }).ToArray(),
                offers);

            _scoringRepository.Add(scoring);
            await _scoringRepository.SaveChangesAsync();

            return(scoring.Id);
        }
Esempio n. 2
0
        public async Task AcceptOfferAsync(long scoringId, long areaId, long expertId)
        {
            var scoring = await _scoringRepository.GetByIdAsync(scoringId);

            if (scoring == null)
            {
                throw new AppErrorException(ErrorCode.ScoringNotFound);
            }

            var expert = await _userRepository.GetByIdAsync(expertId);

            var offer = await GetOfferFromContractAsync(areaId, scoring.ProjectId, expert);

            if (offer == null)
            {
                throw new AppErrorException(ErrorCode.OfferNotFoundInContract);
            }

            scoring.AcceptOffer(expertId, (AreaType)areaId, _clock.UtcNow);

            await _scoringRepository.SaveChangesAsync();
        }
Esempio n. 3
0
        public async Task SaveEstimatesAsync(long expertId, SaveEstimatesRequest request)
        {
            var scoring = await _scoringRepository.GetByProjectIdAsync(request.ProjectId);

            var area = request.AreaType.ToDomain();

            var estimates = request.EstimateComments.Select(x => new Estimate
            {
                Score = x.Score,
                ScoringCriterionId = x.ScoringCriterionId,
                Comment            = x.Comment
            }).ToArray();

            var expertScoring = new ExpertScoring
            {
                ExpertId   = expertId,
                Area       = area,
                Conclusion = request.Conclusion,
                Estimates  = estimates
            };

            scoring.SetExpertScoring(expertId, expertScoring);
            await _scoringRepository.SaveChangesAsync();
        }