Esempio n. 1
0
        public static async Task <QuizUser> GetPBEUserAsync(BiblePathsCoreDbContext context, string LoggedOnUserName)
        {
            // First we'll try to find the user in the DB.
            QuizUser ReturnUser = new QuizUser();

            try
            {
                ReturnUser = await context.QuizUsers.Where(U => U.Email == LoggedOnUserName).SingleAsync();
            }
            catch (InvalidOperationException) // Generally means the user was not found. So Let's add one.
            {
            }
            return(ReturnUser);
        }
Esempio n. 2
0
        public static async Task <QuizUser> GetOrAddPBEUserAsync(BiblePathsCoreDbContext context, string LoggedOnUserName)
        {
            // First we'll try to find the user in the DB.
            QuizUser ReturnUser = new QuizUser();

            try
            {
                ReturnUser = await context.QuizUsers.Where(U => U.Email == LoggedOnUserName).SingleAsync();
            }
            catch (InvalidOperationException) // Generally means the user was not found. So Let's add one.
            {
                //Let's add our user.
                ReturnUser.Email    = LoggedOnUserName;
                ReturnUser.Added    = DateTime.Now;
                ReturnUser.Modified = DateTime.Now;
                context.QuizUsers.Add(ReturnUser);
                await context.SaveChangesAsync();
            }
            return(ReturnUser);
        }
        public async Task <bool> APIUserTokenCheckAsync(BiblePathsCoreDbContext context)
        {
            // Do we have a valid Owner value:
            if (await QuizUser.IsValidPBEQuestionOwnerAsync(context, this.Owner) == false)
            {
                return(false);
            }
            else
            {
                QuizUser PBEUser = await QuizUser.GetPBEUserAsync(context, this.Owner); // Static method not requiring an instance

                if (PBEUser.IsQuestionBuilderLocked)
                {
                    return(false);
                }
                if (await PBEUser.CheckAPITokenAsync(context, this.Token) == true)
                {
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 4
0
        public static async Task <List <SelectListItem> > GetTemplateSelectListAsync(BiblePathsCoreDbContext context, QuizUser QuizUser)
        {
            List <SelectListItem> TemplateSelectList = new List <SelectListItem>();
            List <PredefinedQuiz> Templates          = await context.PredefinedQuizzes
                                                       .Where(T => T.QuizUser == QuizUser && T.IsDeleted == false)
                                                       .ToListAsync();

            // Add a Default entry
            TemplateSelectList.Add(new SelectListItem
            {
                Text  = "<Select a Template>",
                Value = 0.ToString()
            });

            foreach (PredefinedQuiz Template in Templates)
            {
                TemplateSelectList.Add(new SelectListItem
                {
                    Text  = Template.QuizName,
                    Value = Template.Id.ToString()
                });
            }
            return(TemplateSelectList);
        }
 public void CheckUserCanEdit(QuizUser PBEUser)
 {
     UserCanEdit = (Owner == PBEUser.Email || PBEUser.IsModerator);
 }