Ejemplo n.º 1
0
        public string TimeRemain(Guid examId, Guid userId)
        {
            string startTime = scoreRepository.GetTimeStamp(examId, userId);
            bool   isRandom  = examService.IsRandom(examId);

            if (startTime.Equals(String.Empty))
            {
                if (isRandom)
                {
                    scoreRepository.Create(new Score
                    {
                        Id            = Guid.NewGuid(),
                        ExamName      = examRepository.GetRandomExam(examId).Name,
                        RandomExamId  = examId,
                        AnswerContent = String.Empty,
                        Score1        = 0,
                        StartTime     = DateTime.Now.ToString(),
                        UserId        = userId,
                        Time          = String.Empty
                    });

                    return(TimeSpan.FromMinutes(Double.Parse(examRepository.GetRandomExam(examId).Time)).TotalMilliseconds.ToString());
                }
                else
                {
                    scoreRepository.Create(new Score
                    {
                        Id            = Guid.NewGuid(),
                        ExamName      = examRepository.Get(examId).Name,
                        ExamId        = examId,
                        AnswerContent = String.Empty,
                        Score1        = 0,
                        StartTime     = DateTime.Now.ToString(),
                        UserId        = userId,
                        Time          = String.Empty
                    });
                    return(TimeSpan.FromMinutes(Double.Parse(examRepository.Get(examId).Time)).TotalMilliseconds.ToString());
                }
            }
            else
            {
                Score    recordedScore = scoreRepository.Get(examId, userId, isRandom);
                var      timeSpent     = DateTime.Now - DateTime.Parse(startTime);
                TimeSpan examTime      = TimeSpan.FromMinutes(Double.Parse(isRandom ? examRepository.GetRandomExam(examId).Time : examRepository.Get(examId).Time));
                TimeSpan remainTime    = examTime - timeSpent;
                return((timeSpent < examTime && recordedScore.Time.Equals(String.Empty)) ? remainTime.TotalMilliseconds.ToString() : String.Empty);
            }
        }
Ejemplo n.º 2
0
        public void CreateScore(ScoreModel scoreModel)
        {
            var score = _mapper.Map <Score>(scoreModel);

            var topScore = GetTop10Scores().FirstOrDefault();
            var topScorePlayerAchievement = _playerAchievementRepository.Get(score.PlayerId, 3);

            if (score.Result > topScore.Result && topScorePlayerAchievement == null)
            {
                _playerAchievementRepository.Create(score.PlayerId, 3);
            }

            var score3000PlayerAchievement  = _playerAchievementRepository.Get(score.PlayerId, 2);
            var score5000PlayerAchievememnt = _playerAchievementRepository.Get(score.PlayerId, 4);

            if (score.Result >= 3000 && score3000PlayerAchievement == null)
            {
                _playerAchievementRepository.Create(score.PlayerId, 2);
            }

            if (score.Result >= 5000 && score5000PlayerAchievememnt == null)
            {
                _playerAchievementRepository.Create(score.PlayerId, 4);
            }

            _scoreRepository.Create(score);
        }
Ejemplo n.º 3
0
        public ICommandResult Handle(CreateScoreCommand command)
        {
            //Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, Messages.Ex_ExceptionGeneric, command.Notifications));
            }

            //Gera Score
            var Score = new Score(command.Title, command.Stage, command.Value, command.CreateDate, command.PlayerId, command.GameId);

            //Salva no banco
            _repository.Create(Score);

            return(new GenericCommandResult(true, Messages.Act_Save, Score));
        }
Ejemplo n.º 4
0
 public int Create(ScoreVM scoreVM)
 {
     return(scoreRepository.Create(scoreVM));
 }