//POUR VALIDER UNE PROPOSITION EXISTANTE public async Task ConfirmStatement(string observationId, string statementId, string userId, bool isOnlyGenus) { var existingObservation = await this.GetUserObservationbyId(observationId); if (existingObservation == null) { throw new BusinessException("Ce relevé n'existe pas"); } var statement = existingObservation.ObservationStatements.FirstOrDefault(x => x.Id == statementId); if (statement == null) { throw new BusinessException("Cette propostion n'existe pas"); } if (existingObservation.ObservationStatements.Any(s => s.ObservationStatementConfirmations != null && s.ObservationStatementConfirmations.Any(c => c.UserId == userId))) { throw new BusinessException("Vous avez déjà validé une proposition pour ce relevé"); } if (statement.ObservationStatementConfirmations == null) { statement.ObservationStatementConfirmations = new List <ObservationStatementConfirmation>(); } var confirmation = new ObservationStatementConfirmation() { Id = Guid.NewGuid().ToString("N"), Date = DateTime.UtcNow, UserId = userId, Expertise = !isOnlyGenus ? await this.CalculateUserSpeciesExpertise(userId, statement.SpeciesName) : await this.CalculateUserGenusExpertise(userId, statement.Genus), IsOnlyGenus = isOnlyGenus }; statement.ObservationStatementConfirmations.Add(confirmation); statement.TotalScore = statement.CalculateReliabilityStatement(); statement.TotalScoreSpecies = statement.CalculateSpeciesReliabilityStatement(); await this.DataContext.Observations.FindOneAndReplaceAsync(o => o.Id == existingObservation.Id, existingObservation); await this.CalculateKnowledegePoints(observationId, statementId, confirmation.Id); await this.CheckObservationIsIdentify(existingObservation.Id); User user = await this.UsersManager.SelectAsync(userId); var validator = await MissionValidatorFactory.GetValidator(this.ServiceProvider, user); if (validator != null) { await validator?.UpdateMissionProgression(existingObservation, statement, ActionType.ConfirmStatement); } }
public static ObservationStatementConfirmationModel ToObservationStatementConfirmationModel(this ObservationStatementConfirmation observationStatementConfirmation) { return(new ObservationStatementConfirmationModel { Id = observationStatementConfirmation.Id, UserId = observationStatementConfirmation.UserId, Date = observationStatementConfirmation.Date, Expertise = observationStatementConfirmation.Expertise, Confident = (int?)observationStatementConfirmation.Confident, IsOnlyGenus = observationStatementConfirmation.IsOnlyGenus }); }