Beispiel #1
0
        public Object Post([FromBody] QuizUser quizUser)
        {
            logger.Info("Logging user " + quizUser.email);

            dynamic getUser = this.GetByEmail(quizUser.email);

            logger.Info("User by email: " + getUser);

            if (getUser != null)
            {
                logger.Info("User Found: " + getUser.email + " id: " + getUser.id);
                return(getUser);
            }

            QuizDB.QuizUsers.Add(quizUser);
            var savedValue = this.SaveQuizDBChanges(); // QuizDB.SaveChanges();

            Console.WriteLine("Saved Changed !!! " + savedValue);
            return(new
            {
                id = quizUser.id,
                email = quizUser.email,
                name = quizUser.name
            });
        }
Beispiel #2
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync(int Id)
        {
            // confirm our user is a valid PBE User.
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            if (!PBEUser.IsQuizModerator())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to manage a PBE User" }));
            }

            QuizUser UserToUpdate = await _context.QuizUsers.FindAsync(Id);

            if (UserToUpdate == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find this User" }));
            }

            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (await TryUpdateModelAsync <QuizUser>(
                    UserToUpdate,
                    "EditUser",
                    U => U.IsModerator, U => U.IsQuestionBuilderLocked, U => U.IsQuizTakerLocked))
            {
                await _context.SaveChangesAsync();

                return(RedirectToPage("./PBEUsers", new { Message = String.Format("PBE User:  {0} successfully updated...", UserToUpdate.Email) }));
            }
            return(RedirectToPage("./PBEUsers"));
        }
        protected override void UpdateUserProfile(QuizUser user, int bonusExperience, int bonusMoney)
        {
            user.Experience += bonusExperience;
            user.Money      += bonusMoney;

            SaveUserData();
        }
Beispiel #4
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                QuizUser user = new QuizUser {
                    UserName = model.Email, Email = model.Email
                };
                IdentityResult result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    if (model.Administrator)//role!!!!!!!!!
                    {
                        await _userManager.AddClaimAsync(user, new System.Security.Claims.Claim(ClaimTypes.Role, "Administrator"));
                    }

                    return(RedirectToAction("Login", "Account"));
                }

                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            return(View());
        }
 protected Object GetCurrentUserQuestionForReturn(QuizUser user)
 {
     if (user.CurrentUserQuestion != null)
     {
         return(new
         {
             user.CurrentUserQuestion.id,
             user.CurrentUserQuestion.index,
             user.CurrentUserQuestion.isCorrect,
             Question = new
             {
                 user.CurrentUserQuestion.Question.description,
                 user.CurrentUserQuestion.Question.id,
                 user.CurrentUserQuestion.Question.optionType,
                 user.CurrentUserQuestion.Question.imageUrl,
                 QuizOptions = user.CurrentUserQuestion.Question.QuizOptions.Select(quizOption => new
                 {
                     quizOption.description,
                     quizOption.id,
                     quizOption.isCorrect,
                     quizOption.index
                 })
                               .OrderBy(quizOption => quizOption.index)
             },
             user.CurrentUserQuestion.questionId,
             user.CurrentUserQuestion.selectedOptionIds
         });
     }
     else
     {
         return(null);
     }
 }
        public Object Post([FromBody] QuizUser quizUser)
        {
            var  dbQuizUser            = QuizDB.QuizUsers.First(u => u.id == quizUser.id);
            bool?lastQuestionIsCorrect = false;

            if (!quizUser.CurrentUserQuestion.id.Equals(dbQuizUser.CurrentUserQuestion.id))
            {
                throw new ArgumentException("Invalid CurrentUserQuestion");
            }


            var selectedOptions = quizUser.CurrentUserQuestion.selectedOptionIds?.Split(',').OrderBy(s => s);
            var correctOptions  = dbQuizUser.CurrentUserQuestion.Question.QuizOptions.Where(o => o.isCorrect).Select(o => o.id).OrderBy(s => s);

            // first set the isCorrect
            dbQuizUser.CurrentUserQuestion.selectedOptionIds = quizUser.CurrentUserQuestion.selectedOptionIds;
            lastQuestionIsCorrect = dbQuizUser.CurrentUserQuestion.isCorrect = selectedOptions.SequenceEqual(correctOptions);

            this.SetNextQuestion(dbQuizUser);

            if (dbQuizUser.isLastQuestionForCurrentQuiz ?? false)
            {
                //dbQuizUser.CurrentUserQuiz.`
            }

            this.SaveQuizDBChanges();
            return(new
            {
                dbQuizUser.id,
                dbQuizUser.isLastQuestionForCurrentQuiz,
                CurrentUserQuestion = this.GetCurrentUserQuestionForReturn(dbQuizUser),
                lastQuestionIsCorrect = lastQuestionIsCorrect.GetValueOrDefault(),
                quizStatus = dbQuizUser.CurrentUserQuiz.status
            });
        }
        public async Task <IActionResult> OnGetAsync(string BibleId, int Id)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            if (!PBEUser.IsQuizModerator())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to edit a PBE BookList" }));
            }

            BookList = await _context.QuizBookLists.FindAsync(Id);

            if (BookList == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find this Book List" }));
            }

            this.BibleId = await Bible.GetValidPBEBibleIdAsync(_context, BibleId);

            //Initialize Books
            await _context.Entry(BookList).Collection(L => L.QuizBookListBookMaps).LoadAsync();

            BookList.PadBookListBookMapsForEdit();
            Books = BookList.QuizBookListBookMaps.ToList();
            Name  = BookList.BookListName;
            ViewData["BookSelectList"] = await BibleBook.GetBookSelectListAsync(_context, BibleId);

            return(Page());
        }
 protected void Page_Load(object sender, EventArgs e)
 {
     if (User == null)
     {
         User = QuizUser.GetTestUser();
     }
 }
        protected void SetNextQuestion(QuizUser quizUser)
        {
            UserQuestion userQuestion;

            if (quizUser.CurrentUserQuiz == null)
            {
                return;
            }

            if (quizUser.CurrentUserQuestion == null)
            {
                userQuestion = quizUser.CurrentUserQuiz.UserQuestions
                               .OrderBy(q => q.index)
                               .FirstOrDefault();
            }
            else
            {
                userQuestion = quizUser.CurrentUserQuiz.UserQuestions
                               .OrderBy(q => q.index)
                               .Where(q => q.index > quizUser.CurrentUserQuestion.index)
                               .FirstOrDefault();
            }

            //quizUser.isLastQuestionForCurrentQuiz = userQuestion == null;
            quizUser.CurrentUserQuestion = userQuestion;

            if (quizUser.CurrentUserQuestion == null)
            {
                this.SetQuizStatus(quizUser);
            }
        }
        public async Task <IActionResult> OnGetAsync(string BibleId, string Message)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (!PBEUser.IsQuizModerator())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to manage PBE Users" }));
            }

            var pbeUsers = from u in _context.QuizUsers
                           select u;

            if (!string.IsNullOrEmpty(SearchString))
            {
                pbeUsers = pbeUsers.Where(u => u.Email.Contains(SearchString)).OrderBy(u => u.Email).Take(20);
            }
            else
            {
                pbeUsers = pbeUsers.Where(u => u.IsModerator).OrderBy(u => u.Email).Take(20);
            }

            PBEUsers = await pbeUsers.ToListAsync();

            UserMessage = GetUserMessage(Message);
            return(Page());
        }
Beispiel #11
0
        public async Task <IActionResult> OnGetAsync(int Id, string BibleId)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            Template = await _context.PredefinedQuizzes.FindAsync(Id);

            if (Template == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "Thats Odd! We were unable to find this Quiz Template" }));
            }

            if (!PBEUser.IsValidPBEQuestionBuilder() || PBEUser != Template.QuizUser)
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to configure this Quiz Template" }));
            }

            this.BibleId = await Bible.GetValidPBEBibleIdAsync(_context, BibleId);

            //Initialize Our Template
            _context.Entry(Template).Collection(T => T.PredefinedQuizQuestions).Load();
            Questions = Template.IntiQuestionListForAddEdit();
            // Initialize Template Books
            TemplateBooks = await Template.GetTemplateBooksAsync(_context, this.BibleId);

            JSONBooks = JsonSerializer.Serialize(TemplateBooks);
            // Build Select Lists
            foreach (PredefinedQuizQuestion Question in Questions)
            {
                Question.AddChapterSelectList(TemplateBooks);
            }
            ViewData["BookSelectList"] = MinBook.GetMinBookSelectListFromList(TemplateBooks);
            return(Page());
        }
        public Object Post([FromBody] QuizUser quizUser)
        {
            var dbQuizUser = QuizDB.QuizUsers.First(u => u.id == quizUser.id);


            // if there is no quiz assigned or the current quiz is completed then get the next quiz.
            if (dbQuizUser.CurrentUserQuiz == null || dbQuizUser.CurrentUserQuiz.status == QUIZ_STATUS.COMPLETED_FAIL || dbQuizUser.CurrentUserQuiz.status == QUIZ_STATUS.COMPLETED_SUCCESS)
            {
                this.SetNextQuiz(dbQuizUser);
                this.SetNextQuestion(dbQuizUser);
            }

            // ensure that the request quizId is indeed the users next or inprogress quiz.
            if (dbQuizUser.CurrentUserQuiz != null && dbQuizUser.CurrentUserQuiz.status == QUIZ_STATUS.IN_PROGRESS &&
                dbQuizUser.CurrentUserQuiz.Quiz != null && dbQuizUser.CurrentUserQuiz.Quiz.id == quizUser.CurrentUserQuiz.quizId)
            {
                this.SaveQuizDBChanges();
                // return current user
                return(Ok(quizUser));
            }
            else
            {
                //return NotFound();
                throw new NotImplementedException();
            }
        }
        public void GenerateQuizUI(QuizUser user)
        {
            User = user;
            var transactionId = System.Guid.NewGuid().ToString();
            var response      = LNQuizService.GetQuizQuestions(user, transactionId);

            this.lblName.Text     = User.FirstName + " " + User.LastName;
            this.pnlIntro.Visible = true;

            this.QuizQuestions.Questions = response.questions.question.ToList();
            this.QuizQuestions.DataBind();

            this.lblAlert.Text = "Please answer the following questions:";

            this.ViewState.Add("quizId", response.questions.quizId);
            this.ViewState.Add("transactionId", transactionId);

            //foreach(var question in response.questions.question)
            //{
            //    this.txtResponse.InnerText += question.questionId + ":" + question.text + "\n";
            //    foreach(var choice in question.choice)
            //    {
            //        this.txtResponse.InnerText += choice.text + "\n";
            //    }
            //}
        }
Beispiel #14
0
 protected void BeginQuiz_Click(object sender, EventArgs e)
 {
     //TODO: Retreive appropriate Nexis Lexis user here and populate model
     this.Quiz.Visible     = true;
     this.pnlIntro.Visible = false;
     this.Quiz.GenerateQuizUI(QuizUser.GetTestUser());
 }
        /// <summary>
        /// 해당 닉네임을 가진 유저 정보를 새로 등록합니다.
        /// </summary>
        /// <param name="userName">새로 등록될 유저의 닉네임</param>
        /// <returns>퀴즈유저 객체</returns>
        protected new QuizUser AddNewUser(string userName)
        {
            var user = new QuizUser(userName, IsNewUserIgnored, NewUserExperience, NewUserLevel, NewUserMoney, NewUserGeneration, NewUserCurrentTitle, NewUserAvailableTitles);

            Users.Add(user);
            SaveUserData();
            return(user);
        }
Beispiel #16
0
        public async Task <IActionResult> OnGetAsync(int QuestionId, string Caller)
        {
            ReturnPath = Caller;
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (!PBEUser.IsValidPBEQuestionBuilder())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to edit a PBE question" }));
            }

            Question = await _context.QuizQuestions.FindAsync(QuestionId);

            if (Question == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find this Question" }));
            }

            // Setup our PBEBook Object
            Question.BibleId = await QuizQuestion.GetValidBibleIdAsync(_context, Question.BibleId);

            BibleBook PBEBook = await BibleBook.GetPBEBookAndChapterAsync(_context, Question.BibleId, Question.BookNumber, Question.Chapter);

            if (PBEBook == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find the PBE Book." }));
            }

            Question.PopulatePBEQuestionInfo(PBEBook);
            Question.Verses = await Question.GetBibleVersesAsync(_context, false);

            // We need an answer text, and while techincally we support multiple Answers
            // we are only going to allow operating on the first one in this basic edit experience.
            await _context.Entry(Question).Collection(Q => Q.QuizAnswers).LoadAsync();

            if (Question.QuizAnswers.Count > 0)
            {
                AnswerText = Question.QuizAnswers.OrderBy(A => A.Id).First().Answer;
            }
            else
            {
                AnswerText = "";
            }

            IsCommentary = (Question.Chapter == Bible.CommentaryChapter);
            if (IsCommentary == false)
            {
                ChapterQuestionCount = PBEBook.BibleChapters.Where(c => c.ChapterNumber == Question.Chapter).First().QuestionCount;
            }
            CommentaryQuestionCount = PBEBook.CommentaryQuestionCount;

            // and now we need a Verse Select List
            ViewData["VerseSelectList"]  = new SelectList(Question.Verses, "Verse", "Verse");
            ViewData["PointsSelectList"] = Question.GetPointsSelectList();
            return(Page());
        }
        public ActionResult Login(string username, string password)
        {
            var viewModel = new UserViewModel();

            viewModel.Username = username;

            using (QuizEntities context = new QuizEntities())
            {
                context.Database.Exists();
                if (context != null)
                {
                    if (string.IsNullOrWhiteSpace(username) || string.IsNullOrWhiteSpace(password))
                    {
                        viewModel.ErrorMessage = "Incorrect username and/or password!";
                        return(View(viewModel));
                    }

                    var user = _userDal.GetUserByUsername(username);

                    if (user != null && user.ActivStatus)
                    {
                        if (user.Password.Equals(SHA512Encrypter.Encrypt(password), StringComparison.OrdinalIgnoreCase))
                        {
                            FormsAuthentication.SetAuthCookie(user.Username, false);
                            var quizUser = new QuizUser
                            {
                                Id       = user.Id,
                                Username = user.Username,
                                IsAdmin  = user.IsAdmin
                            };
                            if (!user.IsAdmin)
                            {
                                quizUser.TestId = _userTestDal.GetTestIdByUserId(user.Id);
                            }

                            this.Session.Add("QuizUser", quizUser);

                            if (user.IsAdmin)
                            {
                                return(RedirectToAction("StartPageAdmin", "Admin"));
                            }

                            return(RedirectToAction("StartPage", "Quiz"));
                        }
                    }
                    viewModel.ErrorMessage = "Incorrect username and/or password!";
                }
                else
                {
                    viewModel.ErrorMessage = "You are not connect to database";
                }
            }
            return(View(viewModel));
        }
Beispiel #18
0
        public async Task <IActionResult> OnGetAsync()
        {
            PBEUser = new QuizUser();
            if (User.Identity.IsAuthenticated)
            {
                IdentityUser user = await _userManager.GetUserAsync(User);

                PBEUser = await QuizUser.GetPBEUserAsync(_context, user.Email);
            }
            BibleId = Bible.DefaultPBEBibleId;
            return(Page());
        }
Beispiel #19
0
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (await QuizBookList.ListNameAlreadyExistsStaticAsync(_context, Name))
            {
                ModelState.AddModelError("Name", "Sorry, this Name is already in use.");
            }
            if (!ModelState.IsValid)
            {
                ViewData["BookSelectList"] = await BibleBook.GetBookSelectListAsync(_context, BibleId);

                return(Page());
            }

            // confirm our user is a valid PBE User.
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (!PBEUser.IsQuizModerator())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to add a PBE BookList" }));
            }

            // Now let's create an empty BookList
            var emptyBookList = new QuizBookList
            {
                Created  = DateTime.Now,
                Modified = DateTime.Now
            };

            emptyBookList.BookListName = Name;
            emptyBookList.IsDeleted    = false;
            _context.QuizBookLists.Add(emptyBookList);

            // now we need to add the Books
            foreach (int BookNum in Books)
            {
                if (BookNum > 0)
                {
                    QuizBookListBookMap BookMap = new QuizBookListBookMap();
                    BookMap.BookList   = emptyBookList;
                    BookMap.BookNumber = BookNum;
                    BookMap.IsDeleted  = false;
                    BookMap.Created    = DateTime.Now;
                    BookMap.Modified   = DateTime.Now;
                    _context.QuizBookListBookMaps.Add(BookMap);
                    await _context.SaveChangesAsync();
                }
            }
            await _context.SaveChangesAsync();

            return(RedirectToPage("BookLists", new { BibleId = this.BibleId, Message = String.Format("Book List {0} successfully created...", emptyBookList.BookListName) }));
        }
        // To protect from overposting attacks, please enable the specific properties you want to bind to, for
        // more details see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (Quiz.BookNumber == 0 && Quiz.PredefinedQuiz == 0)
            {
                ModelState.AddModelError("Quiz.BookNumber", "You must select either a Book/BookList or a Template.");
                ModelState.AddModelError("Quiz.PredefinedQuiz", "You must select either a Book/BookList or a Template.");
            }
            if (!ModelState.IsValid)
            {
                //Initialize Select Lists
                ViewData["BookSelectList"] = await BibleBook.GetBookAndBookListSelectListAsync(_context, BibleId);

                ViewData["TemplateSelectList"] = await PredefinedQuiz.GetTemplateSelectListAsync(_context, PBEUser);

                return(Page());
            }

            // confirm our user is a valid PBE User.
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (!PBEUser.IsValidPBEQuizHost())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to add a PBE Quiz" }));
            }

            // Now let's create an empty Quiz
            var emptyQuiz = new QuizGroupStat
            {
                Created   = DateTime.Now,
                Modified  = DateTime.Now,
                QuizUser  = PBEUser,
                IsDeleted = false
            };

            if (await TryUpdateModelAsync <QuizGroupStat>(
                    emptyQuiz,
                    "Quiz", // Prefix for form value.
                    q => q.GroupName, q => q.BookNumber, q => q.PredefinedQuiz))
            {
                if (emptyQuiz.PredefinedQuiz > 0)
                {
                    // Template trumps Book/BookList so we set BookNumber 0
                    emptyQuiz.BookNumber = 0;
                }
                _context.QuizGroupStats.Add(emptyQuiz);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Quizzes", new { BibleId = this.BibleId, Message = String.Format("Quiz {0} successfully created...", emptyQuiz.GroupName) }));
        }
        public async Task <IActionResult> OnPostAsync(int?id, string ReturnPath)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Question = await _context.QuizQuestions.FindAsync((int)id.Value);

            if (Question == null)
            {
                return(RedirectToPage("/error", new
                {
                    errorMessage = "That's Odd! We were unable to retrieve this Question... Maybe try that again?"
                }));
            }

            // confirm our user is a valid PBE User.
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (!PBEUser.IsValidPBEQuestionBuilder())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to edit a PBE question" }));
            }

            // Questions and Answers are not actually deleted, because they are used to calculate Stats so we just set to IsDeleted = true.
            if (Question != null)
            {
                _context.Attach(Question).State = EntityState.Modified;
                Question.Modified  = DateTime.Now;
                Question.IsDeleted = true;
                await _context.SaveChangesAsync();
            }
            switch (ReturnPath)
            {
            case "Questions":
                return(RedirectToPage("./Questions", new { BibleId = Question.BibleId, BookNumber = Question.BookNumber, Chapter = Question.Chapter }));

            // break; not needed unreachable

            case "ChallengedQuestions":
                return(RedirectToPage("ChallengedQuestions", new { BibleId = Question.BibleId }));

            // break; not needed unreachable

            default:
                return(RedirectToPage("./Questions", new { BibleId = Question.BibleId, BookNumber = Question.BookNumber, Chapter = Question.Chapter }));
                // break; not needed unreachable
            }
        }
        public async Task <IActionResult> OnGetAsync(string BibleId, int BookNumber, int Chapter, int?Verse)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            this.BookNumber = BookNumber;
            this.Chapter    = Chapter;
            this.Verse      = Verse ?? 0; // set to 0 if Verse is null
            this.BibleId    = await QuizQuestion.GetValidBibleIdAsync(_context, BibleId);

            BibleBook PBEBook = await BibleBook.GetPBEBookAndChapterAsync(_context, this.BibleId, this.BookNumber, this.Chapter);

            if (PBEBook == null)
            {
                return(RedirectToPage("/error", new { errorMessage = "That's Odd! We weren't able to find the PBE Book." }));
            }

            // Handle the possibility that we want only one verse.
            var questions = from q in _context.QuizQuestions select q;

            if (!Verse.HasValue)
            {
                questions = questions.Where(Q => (Q.BibleId == this.BibleId || Q.BibleId == null) && Q.BookNumber == BookNumber && Q.Chapter == Chapter && Q.IsDeleted == false);
            }
            else
            {
                questions = questions.Where(Q => (Q.BibleId == this.BibleId || Q.BibleId == null) && Q.BookNumber == BookNumber && Q.Chapter == Chapter && Q.EndVerse == Verse && Q.IsDeleted == false);
            }

            Questions = await questions.Include(Q => Q.QuizAnswers)
                        .OrderBy(Q => Q.EndVerse)
                        .ToListAsync();

            foreach (QuizQuestion Question in Questions)
            {
                Question.PopulatePBEQuestionInfo(PBEBook);
                Question.CheckUserCanEdit(PBEUser);
            }
            IsCommentary = (this.Chapter == Bible.CommentaryChapter);
            if (IsCommentary)
            {
                this.BookName = PBEBook.CommentaryTitle;
            }
            else
            {
                this.BookName = PBEBook.Name;
            }

            return(Page());
        }
Beispiel #23
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                BookList = await _context.QuizBookLists.Include(B => B.QuizBookListBookMaps).Where(B => B.Id == id).SingleAsync();
            }
            catch {
                return(RedirectToPage("/error", new
                {
                    errorMessage = "That's Odd! We were unable to retrieve this BookList... Maybe try that again"
                }));
            }

            // confirm Path Owner
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (!PBEUser.IsQuizModerator())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to delete a PBE BookList" }));
            }

            // We only ever soft delete a BookList but we do delete the maps.

            // First we need to iterate through each BookList Map and delete them, these are a leaf node so this should be OK.
            foreach (QuizBookListBookMap book in BookList.QuizBookListBookMaps)
            {
                _context.QuizBookListBookMaps.Remove(book);
            }
            await _context.SaveChangesAsync();

            // Let's track this event
            // _ = await Path.RegisterEventAsync(_context, EventType.PathDeleted, Path.Id.ToString());

            // Then we set the BookList to isDeleted
            if (BookList != null)
            {
                _context.Attach(BookList).State = EntityState.Modified;
                BookList.Modified  = DateTime.Now;
                BookList.IsDeleted = true;
                await _context.SaveChangesAsync();
            }
            return(RedirectToPage("./BookLists"));
        }
Beispiel #24
0
        public async Task <IActionResult> OnGetAsync(string BibleId, string Message)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            this.BibleId = await Bible.GetValidPBEBibleIdAsync(_context, BibleId);

            Templates = await _context.PredefinedQuizzes.Include(T => T.PredefinedQuizQuestions)
                        .Where(T => T.IsDeleted == false && T.QuizUser == PBEUser)
                        .ToListAsync();

            UserMessage = GetUserMessage(Message);
            return(Page());
        }
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            try
            {
                Template = await _context.PredefinedQuizzes.Include(T => T.PredefinedQuizQuestions).Where(T => T.Id == id).SingleAsync();
            }
            catch {
                return(RedirectToPage("/error", new
                {
                    errorMessage = "That's Odd! We were unable to retrieve this Template... Maybe try that again?"
                }));
            }

            // confirm Template Owner
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (Template.QuizUser != PBEUser)
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! Only a Template Owner may delete a Template" }));
            }

            // First we need to iterate through each Step and delete them one by one, steps are a leaf node so this should be OK.
            foreach (PredefinedQuizQuestion Question in Template.PredefinedQuizQuestions)
            {
                _context.PredefinedQuizQuestions.Remove(Question);
            }
            await _context.SaveChangesAsync();

            // Let's track this event
            // _ = await Path.RegisterEventAsync(_context, EventType.PathDeleted, Path.Id.ToString());

            // Then we set the Template to isDeleted.
            if (Template != null)
            {
                _context.Attach(Template).State = EntityState.Modified;
                Template.Modified  = DateTime.Now;
                Template.IsDeleted = true;
                await _context.SaveChangesAsync();
            }
            return(RedirectToPage("./Templates"));
        }
        public async Task <IActionResult> OnGetAsync(string Message)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            if (PBEUser.IsQuestionBuilderLocked)
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to create an API token" }));
            }

            TokenString = await PBEUser.GetQuestionAPITokenAsync(_context);

            UserMessage = GetUserMessage(Message);
            return(Page());
        }
        protected void SetNextQuiz(QuizUser quizUser)
        {
            Quiz quiz;
            int  attemptNo = 0;

            if (quizUser.CurrentUserQuiz == null)
            {
                quiz = QuizDB.Quizs.OrderBy(q => q.level).FirstOrDefault();
            }
            else if (quizUser.CurrentUserQuiz.status == QUIZ_STATUS.COMPLETED_SUCCESS)
            {
                quiz = QuizDB.Quizs
                       .OrderBy(q => q.level)
                       .Where(q => q.level > quizUser.CurrentUserQuiz.Quiz.level)
                       .FirstOrDefault();
            }
            else if (quizUser.CurrentUserQuiz.status == QUIZ_STATUS.COMPLETED_FAIL)
            {
                // Reset the CurrentQuiz;
                quiz      = quizUser.CurrentUserQuiz.Quiz;
                attemptNo = quizUser.CurrentUserQuiz.attempt.GetValueOrDefault() + 1;
            }
            else
            {
                throw new NotImplementedException();
            }

            if (quiz == null)
            {
                quizUser.isLastQuiz          = true;
                quizUser.CurrentUserQuiz     = null;
                quizUser.CurrentUserQuestion = null;
                return;
            }

            //quizUser.isLastQuiz = quizList.Count() == 1;
            quizUser.CurrentUserQuiz = new UserQuiz()
            {
                Quiz    = quiz,
                status  = QUIZ_STATUS.IN_PROGRESS.ToString(),
                attempt = attemptNo
            };
            quizUser.UserQuizs.Add(quizUser.CurrentUserQuiz);

            this.GenerateQuizQuestions(quizUser.CurrentUserQuiz);
        }
        private void SetQuizStatus(QuizUser quizUser)
        {
            int passPoint = quizUser.CurrentUserQuiz.Quiz.passpoint.GetValueOrDefault();

            int acquiredPoint = quizUser.CurrentUserQuiz.UserQuestions.Sum(q => {
                if (q.isCorrect.GetValueOrDefault() && COMPLEXITY_POINT.ContainsKey(q.Question.complexity))
                {
                    return(COMPLEXITY_POINT[q.Question.complexity]);
                }
                else
                {
                    return(0);
                }
            });

            quizUser.CurrentUserQuiz.status = acquiredPoint >= passPoint?QUIZ_STATUS.COMPLETED_SUCCESS.ToString() : QUIZ_STATUS.COMPLETED_FAIL.ToString();
        }
Beispiel #29
0
        public async Task <IActionResult> OnGetAsync(string BibleId)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email);

            if (!PBEUser.IsValidPBEQuestionBuilder())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to add a PBE Quiz Template" }));
            }

            this.BibleId = await Bible.GetValidPBEBibleIdAsync(_context, BibleId);

            ViewData["BookSelectList"] = await BibleBook.GetBookAndBookListSelectListAsync(_context, BibleId);

            ViewData["CountSelectList"] = PredefinedQuiz.GetCountSelectList();
            return(Page());
        }
Beispiel #30
0
        public async Task <IActionResult> OnGetAsync(string BibleId)
        {
            IdentityUser user = await _userManager.GetUserAsync(User);

            PBEUser = await QuizUser.GetOrAddPBEUserAsync(_context, user.Email); // Static method not requiring an instance

            if (!PBEUser.IsQuizModerator())
            {
                return(RedirectToPage("/error", new { errorMessage = "Sorry! You do not have sufficient rights to add a PBE BookList" }));
            }

            this.BibleId = await Bible.GetValidPBEBibleIdAsync(_context, BibleId);

            //Initialize Books
            Books = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            ViewData["BookSelectList"] = await BibleBook.GetBookSelectListAsync(_context, BibleId);

            return(Page());
        }