Esempio n. 1
0
    public void Add(AttemptModel model)
    {
        if (attempts == null)
        {
            attempts = new List <AttemptModel> ();
        }

        attempts.Add(model);
    }
        public IActionResult Index()
        {
            Attempt = new AttemptModel();
            List <DefinitionModel> Definitions = _db.Definitions.ToList();
            Random          random             = new Random();
            int             randomIndex        = random.Next(Definitions.Count);
            DefinitionModel definition         = Definitions[randomIndex];

            Attempt.Definition = definition;

            return(View(Attempt));
        }
Esempio n. 3
0
        private void SubmitAttempt()
        {
            AttemptModel am = new AttemptModel();

            am.Date     = DateTime.Now.Date;
            am.Accuracy = Accuracy;
            am.Time     = Time;


            am.TimeString = Time.ToString();
            am.Tutorial   = CurrentTutorial.Name;
            am.WPM        = WPM;
            am.Score      = score;
            InsertAttempt <AttemptModel>(am);
            DisplayTutorialMetrics();
        }
        public IActionResult Index(AttemptModel att)
        {
            Attempt = new AttemptModel();

            var definition = _db.Definitions
                             .FirstOrDefault(u => u.Id == att.Definition.Id);

            Attempt.Definition   = definition;
            Attempt.DefinitionId = definition.Id;
            Attempt.Attempt      = att.Attempt;
            if (definition.Meaning == att.Attempt)
            {
                Attempt.IsCorrect = true;
            }
            else
            {
                Attempt.IsCorrect = false;
            }
            _db.Attempts.Add(Attempt);
            _db.SaveChanges();

            return(RedirectToAction("Index"));
        }
Esempio n. 5
0
        public async Task <IActionResult> Attempt(int quizId, int questionNumber, [Bind("Id,QuizCategory,QuizTitle,AttemptQuestion,AttemptAnswer,CorrectAnswer,UserName")] AttemptModel attempt)
        {
            if (attempt == null)
            {
                return(NotFound());
            }
            else
            {
                var attemptQuiz = await _context.Quizzes.Include(c => c.Category).Include(q => q.Questions).ThenInclude(a => a.Answers)
                                  .FirstOrDefaultAsync(quiz => quiz.Id == quizId);

                var attemptQuestion = attemptQuiz.Questions.FirstOrDefault(q => q.QuestionNumber == questionNumber);

                if (attempt.AttemptAnswer == attemptQuestion.CorrectAnswer)
                {
                    attempt.Subscore = 1;
                }
                else
                {
                    attempt.Subscore = 0;
                }

                if (questionNumber == 1)
                {
                    var resultModel = new ResultModel
                    {
                        QuizCategory = attempt.QuizCategory,
                        QuizTitle    = attempt.QuizTitle,
                        TotalScore   = attempt.Subscore,
                        AttemptDate  = DateTime.Now.ToString("g"),
                        UserName     = attempt.UserName,
                    };

                    _context.Results.Add(resultModel);
                    await _context.SaveChangesAsync();
                }
                else if (questionNumber > 1)
                {
                    var result         = _context.Results.LastOrDefault(u => u.UserName == attempt.UserName);
                    var subscoreUpdate = result.TotalScore + attempt.Subscore;

                    result.TotalScore  = subscoreUpdate;
                    result.AttemptDate = DateTime.Now.ToString("g");

                    _context.Results.LastOrDefault(u => u.UserName == attempt.UserName);
                    _context.Update(result);
                    await _context.SaveChangesAsync();
                }

                attempt.ResultNo = _context.Results.LastOrDefault(u => u.UserName == attempt.UserName).Id;
                _context.Attempts.Add(attempt);
                await _context.SaveChangesAsync();

                var nextQuestion = attemptQuiz.Questions.FirstOrDefault(n => n.QuestionNumber == questionNumber + 1);

                if (nextQuestion == null)
                {
                    return(RedirectToAction("QuizResult", "Quiz", new { resultId = attempt.ResultNo }));
                }
                else
                {
                    return(RedirectToAction("Attempt", "Quiz", new { quizId = quizId, questionNumber = questionNumber + 1 }));
                }
            }
        }
Esempio n. 6
0
        public async Task <ResultStatus> SignInAsync(string userid, string password, bool persist)
        {
            var context = HCA.HttpContext;
            var tup     = ValidateUser(userid);
            var usr     = tup.usr;
            var rslt    = tup.lr;

            if (rslt == Status.Success)
            {
                if (!ComparePasswords(usr, password))
                {
                    usr.IsLogedIn = false;
                    rslt          = Status.WrongPassword;
                    if (usr?.CurrentStatus == AccountStatus.Active)
                    {
                        var atp = AllConsts.FPA.Find(a => a.UserId == usr?.UserId);
                        var an  = new AttemptModel(usr?.UserId);
                        if (atp != null)
                        {
                            an.FaildAttempts += atp.FaildAttempts;
                            AllConsts.FPA.Remove(atp);
                        }
                        AllConsts.FPA.Add(an);

                        if (an.FaildAttempts >= Freshly.D.MaxLoginAttempts)
                        {
                            usr.CurrentStatus = AccountStatus.Locked;
                            usr.LastLockDate  = DateTime.UtcNow;
                        }
                    }
                }
                else
                {
                    var claims = new List <Claim>()
                    {
                        new Claim(ClaimTypes.NameIdentifier, usr.UserId),
                        new Claim(ClaimTypes.Name, usr.UserId),
                        new Claim(ClaimTypes.Role, usr.Groups),
                        new Claim(ClaimTypes.Email, usr.Email),
                        new Claim(ClaimTypes.MobilePhone, usr.PhoneNumber),
                        new Claim("given_name", usr.FirstName),
                        new Claim("family_name", usr.LastName),
                        new Claim("gender", usr.Gender)
                    };

                    var identity = new ClaimsIdentity(AllConsts.AuthenticationType);
                    identity.AddClaims(claims);
                    var principle = new ClaimsPrincipal(identity);

                    //await context.SignInAsync(principle);

                    await context.SignInAsync(
                        CookieAuthenticationDefaults.AuthenticationScheme,
                        principle,
                        new AuthenticationProperties()
                    {
                        IsPersistent = persist
                    });

                    usr.IsLogedIn = true;
                }
                DF.Update(usr);
            }
            return(new ResultStatus(rslt == Status.Success, GetMessage(rslt)));
        }
Esempio n. 7
0
        public ActionResult Attempt(AttemptModel attemptModel)
        {
            AttemptResult result = _gameItemService.SetAttempt(attemptModel.UserId, attemptModel.SelectedNumber);

            return(Json(result.ToString()));
        }