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); }
public async Task UpdateOffersAsync(Guid projectExternalId) { var scoringInfo = await _scoringOffersManagerContractClient.GetScoringInfoAsync(projectExternalId); var experts = await GetExpertsForOffersAsync(scoringInfo.Offers); var expertsDictionary = experts.ToDictionary(e => e.Address, e => e.Id); var project = await _projectRepository.GetByExternalIdAsync(projectExternalId); var scoring = await _scoringRepository.GetByProjectIdAsync(project.Id); var removedOffers = scoring.ScoringOffers .Where(o => !scoringInfo.Offers.Any(e => expertsDictionary[e.ExpertAddress] == o.ExpertId && e.Area == o.AreaId)) .ToArray(); scoring.RemoveOffers(removedOffers); foreach (var offer in scoring.ScoringOffers) { var blockChainOffer = scoringInfo.Offers.FirstOrDefault(x => expertsDictionary[x.ExpertAddress] == offer.ExpertId && x.Area == offer.AreaId); if (blockChainOffer != null && blockChainOffer.Status != offer.Status) { offer.Status = blockChainOffer.Status; } } var newOffers = scoringInfo.Offers .Where(o => !scoring.ScoringOffers.Any(e => e.AreaId == o.Area && e.ExpertId == expertsDictionary[o.ExpertAddress])) .Select(o => new ScoringOffer(expertsDictionary[o.ExpertAddress], o.Area, o.Status)) .ToArray(); if (newOffers.Any()) { scoring.AddOffers(newOffers); await NotifyExpertsAsync(newOffers, experts); } var requiredExpertsCount = await _scoringsRegistryContractClient.GetRequiredExpertsCountsAsync(projectExternalId); scoring.UpdateExpertsCounts(requiredExpertsCount); scoring.AcceptingDeadline = scoringInfo.AcceptingDeadline; scoring.ScoringDeadline = scoringInfo.ScoringDeadline; await _scoringRepository.SaveChangesAsync(); }