Exemplo n.º 1
0
        public ChallengeSolveResult Solve(Challenge challenge, Guid userId, string answer)
        {
            var solveResult = ValidateAnswer(challenge, answer);

            if (solveResult.IsSolved)
            {
                var solver = challenge.Solvers.Single(x => x.UserId == userId);

                solver.HasSolved = true;
                challenge.TimesSolved++;
                var rating = (double)((int)challenge.Difficulty + 1) / challenge.TimesSolved;
                solveResult.RatingObtained = rating;

                identityService.AddRatingToUser(userId, rating);

                unitOfWork.InsertOrUpdate(challenge);
                unitOfWork.InsertOrUpdate(solver);
                unitOfWork.Commit();
            }

            return(solveResult);
        }