public bool CreateFlashCardUserAttempt(FlashCardUserAttemptCreate model)
        {
            var entity =

                new FlashCardUserAttempt()

            {
                Guess             = model.Guess,
                AttemptSuccessful = model.AttemptSuccessful,
                UserCardId        = model.UserFlashCard.UserCardId,
                XPGained          = model.XPGained,
            };

            if (model.Guess.ToLower() != model.UserFlashCard.Word.ToLower())
            {
                model.AttemptSuccessful = false;
            }
            else
            {
                model.AttemptSuccessful = true;
                model.XPGained          = 10;
            }



            using (var ctx = new ApplicationDbContext())
            {
                ctx.FlashCardUserAttempts.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #2
0
        //GET: Create
        //FlashCardUserAttempt/Create

        public ActionResult Create(int id) // id is userCardId from our view
        {
            UserFlashCardService svc = new UserFlashCardService();

            var model = new FlashCardUserAttemptCreate()
            {
                UserFlashCard = svc.GetUserFlashCardById(id),
            };

            return(View(model));
        }
Beispiel #3
0
        public ActionResult Create(FlashCardUserAttemptCreate model)
        {
            var service = CreateFlashCardUserAttemptService();

            service.CreateFlashCardUserAttempt(model);
            if (!model.AttemptSuccessful == true)
            {
                TempData["UnsuccessfulAttempt"] = "Incorrect. Try again!";
                return(View());
            }
            else
            {
                TempData["SuccessfulAttempt"] = "Correct!";
                return(RedirectToAction("Index", "UserFlashCard"));
            }
        }