Esempio n. 1
0
        public void StageNewUserQuestions(string UserName)
        {
            UserBonusQuestion newUserBonusQuestion = new UserBonusQuestion
            {
                UserName       = UserName,
                QuestionNumber = 1,
                QuestionText   = "Is Daenerys (Khaleesi) pregnant?",
                QuestionAnswer = null
            };

            _context.UserBonusQuestion.Add(newUserBonusQuestion);

            newUserBonusQuestion = new UserBonusQuestion
            {
                UserName       = UserName,
                QuestionNumber = 2,
                QuestionText   = "Who kills the Night King?",
                QuestionAnswer = null
            };

            _context.UserBonusQuestion.Add(newUserBonusQuestion);

            newUserBonusQuestion = new UserBonusQuestion
            {
                UserName       = UserName,
                QuestionNumber = 3,
                QuestionText   = "Who will hold the Iron Throne at the end?",
                QuestionAnswer = null
            };

            _context.UserBonusQuestion.Add(newUserBonusQuestion);

            _context.SaveChanges();
            return;
        }
        public async Task <IActionResult> Create([Bind("UserBonusQuestionID,UserName,QuestionNumber,QuestionText,QuestionAnswer,Correct")] UserBonusQuestion userBonusQuestion)
        {
            if (ModelState.IsValid)
            {
                _context.Add(userBonusQuestion);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(userBonusQuestion));
        }
        public async Task <IActionResult> Edit(int id, [Bind("UserBonusQuestionID,UserName,QuestionNumber,QuestionText,QuestionAnswer,Correct")] UserBonusQuestion userBonusQuestion)
        {
            if (id != userBonusQuestion.UserBonusQuestionID)
            {
                return(NotFound());
            }
            string username = HttpContext.User.Identity.Name;

            if (admins.Contains(username))
            {
                if (ModelState.IsValid)
                {
                    try
                    {
                        _context.Update(userBonusQuestion);
                        await _context.SaveChangesAsync();
                    }
                    catch (DbUpdateConcurrencyException)
                    {
                        if (!UserBonusQuestionExists(userBonusQuestion.UserBonusQuestionID))
                        {
                            return(NotFound());
                        }
                        else
                        {
                            throw;
                        }
                    }
                    return(RedirectToAction(nameof(Index)));
                }
            }
            else
            {
                return(Unauthorized());
            }
            return(View(userBonusQuestion));
        }