/// <inheritdoc cref="ITrainingSessionService.PostOrganismsScoreAsync(PostOrganismsScoreRequest)"/>
        public async Task <PostOrganismsScoreResponse> PostOrganismsScoreAsync(PostOrganismsScoreRequest postOrganismsScoreRequest)
        {
            TrainingSession trainingSession = await _trainingSessionRepository.FindSingleOrDefaultAsync(p => p.Id.Equals(postOrganismsScoreRequest.TrainingSessionId));

            if (trainingSession == default)
            {
                return(new PostOrganismsScoreResponse(postOrganismsScoreRequest.Id, "Training session does not exist."));
            }
            int count = 0;

            List <LeasedOrganism> orgs = postOrganismsScoreRequest.OrganismScores
                                         .Select(o =>
            {
                LeasedOrganism oo = trainingSession.LeasedOrganisms.SingleOrDefault(a => a.OrganismId.Equals(o.Key));
                if (oo == default)
                {
                    count++;
                }
                return(oo);
            }).ToList();

            if (count > 0)
            {
                return(new PostOrganismsScoreResponse(postOrganismsScoreRequest.Id, $"{count} of the organisms does not exist in the training session."));
            }

            foreach (LeasedOrganism leasedOrganism in orgs)
            {
                leasedOrganism.Organism.Score       = postOrganismsScoreRequest.OrganismScores.Find(o => o.Key == leasedOrganism.OrganismId).Value;
                leasedOrganism.Organism.IsEvaluated = true;
            }

            await _trainingSessionRepository.SaveChangesAsync();

            _logger.LogInformation("UPDATED ORGANISM SCORES!!!");

            string message = "Successfully updated the organisms scores.";

            if (trainingSession.TrainingRoom.AllOrganismsInCurrentGenerationAreEvaluated())
            {
                trainingSession.LeasedOrganisms.Clear();
                await _trainingSessionRepository.SaveChangesAsync();

                _logger.LogInformation("CLEARED LEASED ORGANISMS AND SAVED CHANGES!!!");

                trainingSession.TrainingRoom.EndGeneration(
                    (organism) => _trainingSessionRepository.MarkOrganismForRemoval(organism),
                    (species) => _trainingSessionRepository.MarkSpeciesForRemoval(species));

                message = "Successfully updated the organisms and advanced a generation!";

                await _trainingSessionRepository.UpdateOrganismsAsync(trainingSession);

                _logger.LogInformation("ENDED THE GENERATION!!!");
            }
            return(new PostOrganismsScoreResponse(postOrganismsScoreRequest.Id, message, true));
        }
        /// <inheritdoc cref="ITrainingRoomService.PostOrganismsScoreAsync(PostOrganismsScoreRequest)"/>
        public async Task <PostOrganismsScoreResponse> PostOrganismsScoreAsync(PostOrganismsScoreRequest postOrganismsScoreRequest)
        {
            TrainingSession trainingSession = await _trainingSessionRepository.FindSingleOrDefaultAsync(p => p.Id.Equals(postOrganismsScoreRequest.TrainingSessionId));

            if (trainingSession == default)
            {
                return(new PostOrganismsScoreResponse(postOrganismsScoreRequest.Id, "Training session does not exist."));
            }
            int count = 0;

            List <LeasedOrganism> orgs = postOrganismsScoreRequest.OrganismScores
                                         .Select(o =>
            {
                LeasedOrganism oo = trainingSession.LeasedOrganisms.SingleOrDefault(a => a.OrganismId.Equals(o.Key));
                if (oo == default)
                {
                    count++;
                }
                return(oo);
            }).ToList();

            if (count > 0)
            {
                return(new PostOrganismsScoreResponse(postOrganismsScoreRequest.Id, $"{count} of the organisms does not exist in the training session."));
            }

            foreach (LeasedOrganism leasedOrganism in orgs)
            {
                trainingSession.TrainingRoom.PostScore(leasedOrganism.Organism, postOrganismsScoreRequest.OrganismScores[leasedOrganism.OrganismId]);
            }

            string message = "Successfully updated the organisms scores.";

            if (trainingSession.TrainingRoom.Species.SelectMany(p => p.Organisms).All(lo => lo.Evaluated))
            {
                message = trainingSession.TrainingRoom.EndGeneration()
                    ? "Successfully updated the organisms and advanced a generation!"
                    : "Successfully updated the organisms but failed to advance a generation!";
                trainingSession.LeasedOrganisms.Clear();
            }
            await _trainingSessionRepository.UpdateAsync(trainingSession);

            return(new PostOrganismsScoreResponse(postOrganismsScoreRequest.Id, message, true));
        }