public async Task ProcessNewTryAsync(Guid routeId, string userId, RankingRecordDto rankingRecordDto) { var route = await _routesRepository.GetRouteAsync(routeId); var currentRankingRecord = route.Ranking.SingleOrDefault(rr => rr.UserId == Guid.Parse(userId)); if (currentRankingRecord == null) { var newRankingRecord = _mapper.Map <RankingRecord>(rankingRecordDto); newRankingRecord.UserId = Guid.Parse(userId); route.Ranking.Add(newRankingRecord); } else { if (currentRankingRecord.FinalResult < rankingRecordDto.CheckpointsTimes.Last()) { return; } _mapper.Map(rankingRecordDto, currentRankingRecord); } await _routesRepository.UpdateAsync(); }
public async Task <IActionResult> CreateRankingRecord(Guid routeId, RankingRecordDto rankingRecordDto) { await _routeService.ProcessNewTryAsync(routeId, CurrentUserId, rankingRecordDto); return(Ok()); }