Пример #1
0
 public async Task <bool> SaveNewQuiz(Quiz quiz)
 {
     using (var context = new AssessmentToolContext())
     {
         context.Quizzes.Add(quiz);
         return(await context.SaveChangesAsync() > 0);
     }
 }
Пример #2
0
        public async Task <bool> UpdateQuiz(Quiz quiz)
        {
            using (var context = new AssessmentToolContext())
            {
                context.Entry(quiz).State = System.Data.Entity.EntityState.Modified;

                return(await context.SaveChangesAsync() > 0);
            }
        }
        public async Task <bool> NewStudentQuiz(StudentQuiz studentQuiz)
        {
            using (var context = new AssessmentToolContext())
            {
                context.StudentQuizzes.Add(studentQuiz);

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #4
0
        public async Task <bool> SaveNewQuestion(Question question)
        {
            using (var context = new AssessmentToolContext())
            {
                context.Questions.Add(question);

                return(await context.SaveChangesAsync() > 0);
            }
        }
        public async Task <bool> NewAttemptedQuestion(AttemptedQuestion attemptedQuestion)
        {
            using (var context = new AssessmentToolContext())
            {
                context.AttemptedQuestions.Add(attemptedQuestion);

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #6
0
        public async Task <bool> NewRole(IdentityRole role)
        {
            using (var context = new AssessmentToolContext())
            {
                context.Roles.Add(role);

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #7
0
        public async Task <bool> DeleteQuestion(Question question)
        {
            using (var context = new AssessmentToolContext())
            {
                context.Questions.Attach(question);

                context.Options.RemoveRange(question.Options);
                context.Questions.Remove(question);

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #8
0
        public async Task <bool> DeleteQuiz(Quiz quiz)
        {
            using (var context = new AssessmentToolContext())
            {
                context.Quizzes.Attach(quiz);

                quiz.Questions.ForEach(qu => context.Options.RemoveRange(qu.Options));
                context.Questions.RemoveRange(quiz.Questions);
                context.Quizzes.Remove(quiz);

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #9
0
        public async Task <bool> DeleteRole(string ID)
        {
            using (var context = new AssessmentToolContext())
            {
                var role = context.Roles.Find(ID);

                if (role != null)
                {
                    context.Entry(role).State = System.Data.Entity.EntityState.Deleted;
                }

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #10
0
        //public async Task<bool> NewUser(AssessmentToolUser user)
        //{
        //    using (var context = new AssessmentToolContext())
        //    {
        //        context.Users.Add(user);

        //        return await context.SaveChangesAsync() > 0;
        //    }
        //}

        public async Task <bool> UpdateRole(IdentityRole role)
        {
            using (var context = new AssessmentToolContext())
            {
                var oldRole = context.Roles.Find(role.Id);

                if (oldRole != null)
                {
                    oldRole.Name = role.Name;

                    context.Entry(oldRole).State = System.Data.Entity.EntityState.Modified;
                }

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #11
0
        public async Task <bool> UpdateQuestion(Question question)
        {
            using (var context = new AssessmentToolContext())
            {
                //get the question by ID
                var oldQuestion = context.Questions.Find(question.ID);

                //delete this old question with all options
                context.Options.RemoveRange(oldQuestion.Options);
                context.Questions.Remove(oldQuestion);

                //add a new question with new options
                context.Questions.Add(question);

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #12
0
        public async Task <bool> RemoveUserRole(string userID, string roleID)
        {
            using (var context = new AssessmentToolContext())
            {
                var user = context.Users.Find(userID);

                if (user != null)
                {
                    var userRole = user.Roles.Where(r => r.RoleId == roleID).FirstOrDefault();

                    if (user != null)
                    {
                        user.Roles.Remove(userRole);
                    }
                }

                return(await context.SaveChangesAsync() > 0);
            }
        }
Пример #13
0
        public async Task <bool> AddUserRole(string userID, string roleID)
        {
            using (var context = new AssessmentToolContext())
            {
                var user = context.Users.Find(userID);

                var role = context.Roles.Find(roleID);

                if (user != null && role != null)
                {
                    user.Roles.Add(new IdentityUserRole()
                    {
                        UserId = userID, RoleId = roleID
                    });
                }

                return(await context.SaveChangesAsync() > 0);
            }
        }